Introduce a WaypointList class to define the interface to our lists of waypoints...
authortsteven4 <tsteven4@users.noreply.github.com>
Sat, 16 Mar 2019 14:40:10 +0000 (08:40 -0600)
committerGitHub <noreply@github.com>
Sat, 16 Mar 2019 14:40:10 +0000 (08:40 -0600)
* Introduce a WaypointList class to define the interface to our lists of waypoints.

WaypointList is backed QList, eliminating the use of legacy queues for waypoint lists.

* try to appease xcode wrt std::abs.

* clean up inheritence in WaypointList, RouteList.

also quiet clazy with igc and gpsbabel_optional::optional.
also improve includes in defs.h.

* get rid of unnecessary reinterpret_cast.

and correct pointer constness lost by auto.

43 files changed:
arcdist.cc
bcr.cc
bend.cc
bend.h
defs.h
dmtlog.cc
duplicate.cc
filterdefs.h
garmin.cc
gdb.cc
ggv_log.cc
ggv_ovl.cc
gpx.cc
igc.cc
interpolate.cc
kml.cc
lowranceusr.cc
magproto.cc
main.cc
mapasia.cc
mapsend.cc
mapsource.cc
mmo.cc
netstumbler.cc
nmea.cc
pocketfms_fp.cc
polygon.cc
position.cc
position.h
psitrex.cc
radius.cc
reverse_route.cc
route.cc
sort.cc
sort.h
stackfilter.cc
stackfilter.h
tomtom.cc
tpo.cc
trackfilter.cc
trackfilter.h
transform.cc
waypt.cc

index e929b10ec0d987e2a83aadaddc08257d9c3b57b9..ee9dc06df27bb5fcf33226de0ac025e92a6cd782 100644 (file)
@@ -42,13 +42,7 @@ void ArcDistanceFilter::arcdist_arc_disp_wpt_cb(const Waypoint* arcpt2)
   if (arcpt2 && arcpt2->latitude != BADVAL && arcpt2->longitude != BADVAL &&
       (ptsopt || (arcpt1 &&
                   (arcpt1->latitude != BADVAL && arcpt1->longitude != BADVAL)))) {
-#if NEWQ
-    foreach (Waypoint* waypointp, waypt_list) {
-#else
-    queue* elem, *tmp;
-    QUEUE_FOR_EACH(&waypt_head, elem, tmp) {
-      Waypoint* waypointp = reinterpret_cast<Waypoint*>(elem);
-#endif
+    foreach (Waypoint* waypointp, *global_waypoint_list) {
       double dist;
       extra_data* ed;
       if (waypointp->extra_data) {
@@ -107,8 +101,6 @@ void ArcDistanceFilter::process()
   WayptFunctor<ArcDistanceFilter> arcdist_arc_disp_wpt_cb_f(this, &ArcDistanceFilter::arcdist_arc_disp_wpt_cb);
   RteHdFunctor<ArcDistanceFilter> arcdist_arc_disp_hdr_cb_f(this, &ArcDistanceFilter::arcdist_arc_disp_hdr_cb);
 
-  queue* elem, * tmp;
-
   if (arcfileopt) {
     int fileline = 0;
     char* line;
@@ -154,12 +146,7 @@ void ArcDistanceFilter::process()
   }
 
   unsigned removed = 0;
-#if NEWQ
-  foreach (Waypoint* wp, waypt_list) {
-#else
-  QUEUE_FOR_EACH(&waypt_head, elem, tmp) {
-    Waypoint* wp = reinterpret_cast<Waypoint *>(elem);
-#endif
+  foreach (Waypoint* wp, *global_waypoint_list) {
     extra_data* ed = (extra_data*) wp->extra_data;
     wp->extra_data = nullptr;
     if (ed) {
diff --git a/bcr.cc b/bcr.cc
index d0814f468cbeb5c27c6b8b86dc395aa0e08d6c23..f17232871674c0d3f6d54ea18ae789c05257a86b 100644 (file)
--- a/bcr.cc
+++ b/bcr.cc
     2007/04&14: new handling of DESCRIPTION lines
 */
 
+#include <cmath>            // for M_PI, atan, exp, log, tan
+#include <cstdio>           // for printf, snprintf, sscanf
+#include <cstdlib>          // for atof, atoi
+
+#include <QtCore/QString>   // for QString, operator+
+#include <QtCore/Qt>        // for CaseInsensitive
+#include <QtCore/QtGlobal>  // for foreach
+
 #include "defs.h"
-#include "csv_util.h"
-#include "garmin_tables.h"
-#include "inifile.h"
-#include <QtCore/QString>
-#include <cmath>
-#include <cstdio>
-#include <cstdlib>
+#include "csv_util.h"       // for csv_stringclean
+#include "garmin_tables.h"  // for gt_find_desc_from_icon_number, gt_find_icon_number_from_desc, MAPSOURCE
+#include "gbfile.h"         // for gbfprintf, gbfclose, gbfopen, gbfile
+#include "inifile.h"        // for inifile_readstr, inifile_done, inifile_init, inifile_t
+
 
 #define MYNAME "bcr"
 
@@ -201,11 +207,8 @@ bcr_rd_deinit()
 static void
 bcr_create_waypts_from_route(route_head* route)
 {
-  queue* elem, *tmp;
-
-  QUEUE_FOR_EACH(&route->waypoint_list, elem, tmp) {
-    Waypoint* wpt = new Waypoint(*reinterpret_cast<Waypoint *>(elem));
-    waypt_add(wpt);
+  foreach (const Waypoint* wpt, route->waypoint_list) {
+    waypt_add(new Waypoint(*wpt));
   }
 }
 
@@ -350,8 +353,6 @@ static void bcr_write_line(gbfile* fout, const QString& key, const int* index, c
 static void
 bcr_route_header(const route_head* route)
 {
-  queue* elem, *tmp;
-  Waypoint* wpt;
   int north, east, nmax, emin;
 
   curr_rte_num++;
@@ -375,8 +376,7 @@ bcr_route_header(const route_head* route)
   bcr_write_line(fout, "DESCRIPTIONLINES", nullptr, "0");
 
   int i = 0;
-  QUEUE_FOR_EACH(&route->waypoint_list, elem, tmp) {
-    Waypoint* wpt = reinterpret_cast<Waypoint *>(elem);
+  foreach (const Waypoint* wpt, route->waypoint_list) {
 
     i++;
 
@@ -392,9 +392,8 @@ bcr_route_header(const route_head* route)
   int emax = nmax = -nmin;
 
   i = 0;
-  QUEUE_FOR_EACH(&route->waypoint_list, elem, tmp) {
+  foreach (const Waypoint* wpt, route->waypoint_list) {
     i++;
-    wpt = reinterpret_cast<Waypoint *>(elem);
 
     bcr_wgs84_to_mercator(wpt->latitude, wpt->longitude, &north, &east);
 
@@ -418,11 +417,10 @@ bcr_route_header(const route_head* route)
   bcr_write_line(fout, "[DESCRIPTION]", nullptr, nullptr);             /* descr. section */
 
   i = 0;
-  QUEUE_FOR_EACH(&route->waypoint_list, elem, tmp) {
+  foreach (const Waypoint* wpt, route->waypoint_list) {
     QString s2;
 
     i++;
-    wpt = reinterpret_cast<Waypoint *>(elem);
     QString s1 = wpt->notes;
     if (s1.isEmpty()) {
       s1 = wpt->description;
diff --git a/bend.cc b/bend.cc
index d794ee1d67c39996519140d6f2cdb4ee0f2c6a26..92f4b34029e549cd7e82480cbe7b9a5c7d8c0bc9 100644 (file)
--- a/bend.cc
+++ b/bend.cc
 
  */
 
+#include <cmath>            // macos wants abs from here!
+#include <cstdlib>          // for strtod, abs
+
+#include <QtCore/QString>   // for QString
+#include <QtCore/QtGlobal>  // for qAsConst, QAddConst<>::Type, foreach
+
 #include "defs.h"
-#include "bend.h"
 #include "filterdefs.h"
-#include "grtcirc.h"
+#include "bend.h"
+#include "grtcirc.h"        // for RAD, heading_true_degrees, gcdist, linepart, radtometers, DEG
 
-#include <cmath>
-#include <cstdlib>
 
 #define MYNAME "bend"
 
@@ -90,12 +94,10 @@ int BendFilter::is_small_angle(double lat_orig, double long_orig, double lat_ori
 
 void BendFilter::process_route(const route_head* route_orig, route_head* route_dest)
 {
-  Waypoint* wpt_orig_prev = nullptr;
-  Waypoint* wpt_orig = nullptr;
+  const Waypoint* wpt_orig_prev = nullptr;
+  const Waypoint* wpt_orig = nullptr;
 
-  queue* elem, *tmp;
-  QUEUE_FOR_EACH(&route_orig->waypoint_list, elem, tmp) {
-    Waypoint* wpt_orig_next = reinterpret_cast<Waypoint *>(elem);
+  foreach (const Waypoint* wpt_orig_next, route_orig->waypoint_list) {
 
     if (wpt_orig_prev == nullptr) {
       if (wpt_orig != nullptr) {
@@ -158,8 +160,7 @@ void BendFilter::process_route_orig(const route_head* route_orig)
 
 void BendFilter::process()
 {
-  for (auto it = routes_orig->cbegin(); it != routes_orig->cend(); ++it) {
-    auto route_orig = reinterpret_cast<const route_head*>(*it);
+  for (const auto* route_orig : qAsConst(*routes_orig)) {
     process_route_orig(route_orig);
   }
 }
diff --git a/bend.h b/bend.h
index 904c02999a1e67844f49c97406e9641460ddcfd4..a9048b99ff1e9e7dd6eeeaea41d04daa6cd7f4ca 100644 (file)
--- a/bend.h
+++ b/bend.h
@@ -25,7 +25,6 @@
 
 #include "defs.h"    // for route_head (ptr only), ARGTYPE_FLOAT, ARG_NOMINMAX
 #include "filter.h"  // for Filter
-#include "queue.h"   // for queue
 
 #if FILTERS_ENABLED
 
diff --git a/defs.h b/defs.h
index 3e877717998fbcd053f571b722352418f893bbfe..c51baeeb4173c70a382ccd5ccae46450ecb7278b 100644 (file)
--- a/defs.h
+++ b/defs.h
 #ifndef DEFS_H_INCLUDED_
 #define DEFS_H_INCLUDED_
 
-#include <cstdint>
+#include <cmath>                // for M_PI
+#include <cstdarg>              // for va_list
+#include <cstddef>              // for NULL, nullptr_t, size_t
+#include <cstdint>              // for int32_t, uint32_t
+#include <cstdio>               // for NULL, fprintf, FILE, stdout
+#include <ctime>                // for time_t
+#include <utility>              // for move
 
 #if HAVE_CONFIG_H
 #include "config.h"
 #endif
-#include "queue.h"
 #if HAVE_LIBZ
-#include <zlib.h>
+#include <zlib.h>               // doesn't really belong here, but is missing elsewhere.
 #elif !ZLIB_INHIBITED
-#include "zlib.h"
+#include "zlib.h"               // doesn't really belong here, but is missing elsewhere.
 #endif
-#include "gbfile.h"
-#include "inifile.h"
-#include "session.h"
 
-#include <QtCore/QString>
-#include <QtCore/QTextCodec>
-#include <utility>
-#include "src/core/datetime.h"
-#include "src/core/optional.h"
+#include <QtCore/QByteArray>    // for QByteArray
+#include <QtCore/QChar>         // for QChar
+#include <QtCore/QList>         // for QList, QList<>::const_reverse_iterator, QList<>::reverse_iterator
+#include <QtCore/QString>       // for QString
+#include <QtCore/QStringRef>    // for QStringRef
+#include <QtCore/QTextCodec>    // for QTextCodec
+#include <QtCore/Qt>            // for CaseInsensitive
+#include <QtCore/QtGlobal>      // for foreach
+
+#include "cet.h"                // for cet_cs_vec_t
+#include "inifile.h"            // for inifile_t
+#include "gbfile.h"             // doesn't really belong here, but is missing elsewhere.
+#include "queue.h"              // for queue
+#include "session.h"            // for session_t
+#include "src/core/datetime.h"  // for DateTime
+#include "src/core/optional.h"  // for optional
+
 
 #define CSTR(qstr) ((qstr).toUtf8().constData())
 #define CSTRc(qstr) ((qstr).toLatin1().constData())
@@ -457,8 +471,6 @@ private:
   static geocache_data empty_gc_data;
 
 public:
-  queue Q;                     /* Master waypoint q.  Not for use
-                                          by modules. */
 
   double latitude;             /* Degrees */
   double longitude;            /* Degrees */
@@ -561,13 +573,57 @@ public:
 
 typedef void (*waypt_cb)(const Waypoint*);
 
+// TODO: Consider using composition instead of private inheritance.
+class WaypointList : private QList<Waypoint*>
+{
+public:
+  typedef bool (*Compare)(const Waypoint* a, const Waypoint* b);
+
+  void waypt_add(Waypoint* wpt); // a.k.a. append(), push_back()
+  void add_rte_waypt(int waypt_ct, Waypoint* wpt, bool synth, const QString& namepart, int number_digits);
+  // FIXME: Generally it is inefficient to use an element pointer or reference to define the element to be deleted, use iterator instead,
+  //        and/or implement pop_back() a.k.a. removeLast(), and/or pop_front() a.k.a. removeFirst().
+  void waypt_del(Waypoint* wpt); // a.k.a. erase()
+  // FIXME: Generally it is inefficient to use an element pointer or reference to define the element to be deleted, use iterator instead,
+  //        and/or implement pop_back() a.k.a. removeLast(), and/or pop_front() a.k.a. removeFirst().
+  void del_rte_waypt(Waypoint* wpt);
+  void waypt_compute_bounds(bounds* bounds) const;
+  Waypoint* find_waypt_by_name(const QString& name) const;
+  void flush(); // a.k.a. clear()
+  void copy(WaypointList** dst) const;
+  void restore(WaypointList* src);
+  void swap(WaypointList& other);
+  void sort(Compare cmp);
+  template <typename T>
+  void waypt_disp_session(const session_t* se, T cb);
+
+  // Expose limited methods for portability.
+  // public types
+  using QList<Waypoint*>::const_iterator;
+  using QList<Waypoint*>::const_reverse_iterator;
+  using QList<Waypoint*>::iterator;
+  using QList<Waypoint*>::reverse_iterator;
+  // public functions
+  using QList<Waypoint*>::back; // a.k.a. last()
+  using QList<Waypoint*>::begin;
+  using QList<Waypoint*>::cbegin;
+  using QList<Waypoint*>::cend;
+  using QList<Waypoint*>::count; // a.k.a. size()
+  using QList<Waypoint*>::crbegin;
+  using QList<Waypoint*>::crend;
+  using QList<Waypoint*>::empty; // a.k.a. isEmpty()
+  using QList<Waypoint*>::end;
+  using QList<Waypoint*>::front; // a.k.a. first()
+  using QList<Waypoint*>::rbegin;
+  using QList<Waypoint*>::rend;
+};
+
 const global_trait* get_traits();
 void waypt_init();
 //void update_common_traits(const Waypoint* wpt);
 void waypt_add(Waypoint* wpt);
 void waypt_del(Waypoint* wpt);
 unsigned int waypt_count();
-void set_waypt_count(unsigned int nc);
 void waypt_disp(const Waypoint* wpt);
 void waypt_status_disp(int total_ct, int myct);
 //void waypt_disp_all(waypt_cb); /* template */
@@ -577,10 +633,12 @@ int waypt_bounds_valid(bounds* bounds);
 void waypt_add_to_bounds(bounds* bounds, const Waypoint* waypointp);
 void waypt_compute_bounds(bounds* bounds);
 Waypoint* find_waypt_by_name(const QString& name);
-void waypt_flush(queue* head);
 void waypt_flush_all();
-void waypt_backup(signed int* count, queue** head_bak);
-void waypt_restore(signed int count, queue* head_bak);
+void waypt_append(WaypointList* src);
+void waypt_backup(WaypointList** head_bak);
+void waypt_restore(WaypointList* head_bak);
+void waypt_swap(WaypointList& other);
+void waypt_sort(WaypointList::Compare cmp);
 void waypt_add_url(Waypoint* wpt, const QString& link,
                    const QString& url_link_text);
 void waypt_add_url(Waypoint* wpt, const QString& link,
@@ -598,17 +656,10 @@ double waypt_course(const Waypoint* A, const Waypoint* B);
 
 template <typename T>
 void
-waypt_disp_session(const session_t* se, T cb)
+WaypointList::waypt_disp_session(const session_t* se, T cb)
 {
-  extern queue waypt_head;
   int i = 0;
-#if NEWQ
-  foreach (Waypoint* waypointp, waypt_list) {
-#else
-  queue* elem, *tmp;
-  QUEUE_FOR_EACH(&waypt_head, elem, tmp) {
-    Waypoint* waypointp = reinterpret_cast<Waypoint*>(elem);
-#endif
+  foreach (Waypoint* waypointp, *this) {
     if ((se == nullptr) || (waypointp->session == se)) {
       if (global_opts.verbose_status) {
         i++;
@@ -622,11 +673,22 @@ waypt_disp_session(const session_t* se, T cb)
   }
 }
 
+template <typename T>
+void
+waypt_disp_session(const session_t* se, T cb)
+{
+  extern WaypointList* global_waypoint_list;
+
+  global_waypoint_list->waypt_disp_session(se, cb);
+}
+
 template <typename T>
 void
 waypt_disp_all(T cb)
 {
-  waypt_disp_session(nullptr, cb);
+  extern WaypointList* global_waypoint_list;
+
+  global_waypoint_list->waypt_disp_session(nullptr, cb);
 }
 
 /*
@@ -650,7 +712,7 @@ struct computed_trkdata {
 class route_head
 {
 public:
-  queue waypoint_list; /* List of child waypoints */
+  WaypointList waypoint_list;  /* List of child waypoints */
   QString rte_name;
   QString rte_desc;
   UrlList rte_urls;
@@ -710,18 +772,24 @@ public:
   // Our contained element (route_head) also contains a container (waypoint_list), 
   // and we maintain a total count the elements in these contained containers, i.e.
   // the total number of waypoints in all the routes in the RouteList.
+  // public types
+  using QList<route_head*>::const_iterator;
+  using QList<route_head*>::const_reverse_iterator;
+  using QList<route_head*>::iterator;
+  using QList<route_head*>::reverse_iterator;
+  // public functions
+  using QList<route_head*>::back; // a.k.a. last()
   using QList<route_head*>::begin;
-  using QList<route_head*>::end;
   using QList<route_head*>::cbegin;
   using QList<route_head*>::cend;
+  using QList<route_head*>::count; // a.k.a. size()
+  using QList<route_head*>::crbegin;
+  using QList<route_head*>::crend;
   using QList<route_head*>::empty; // a.k.a. isEmpty()
+  using QList<route_head*>::end;
   using QList<route_head*>::front; // a.k.a. first()
-  using QList<route_head*>::back;  // a.k.a. last()
-  using QList<route_head*>::count;  // a.k.a. size()
-  using QList<route_head*>::iterator;
-  using QList<route_head*>::const_iterator;
-  typedef iterator Iterator;
-  typedef const_iterator ConstIterator;
+  using QList<route_head*>::rbegin;
+  using QList<route_head*>::rend;
 
 private:
   int waypt_ct{0};
@@ -767,11 +835,8 @@ template <typename T>
 void
 route_disp(const route_head* rh, T cb)
 {
-  queue* elem, *tmp;
 // cb != nullptr, caught with an overload of route_disp
-  QUEUE_FOR_EACH(&rh->waypoint_list, elem, tmp) {
-    Waypoint* waypointp;
-    waypointp = reinterpret_cast<Waypoint*>(elem);
+  foreach (const Waypoint* waypointp, rh->waypoint_list) {
     cb(waypointp);
   }
 }
index a606055b93b415e8c87170947645c6b3ea7f482f..9dfc30f700b2dd1878c77303e50d63ef1e17dc16 100644 (file)
--- a/dmtlog.cc
+++ b/dmtlog.cc
 
  */
 
-#include <QtCore/QXmlStreamAttributes>
+#include <cstdio>                       // for SEEK_CUR, size_t
+#include <cstdint>                      // int32_t, int16_t, uint32_t
+#include <cstdlib>                      // for atoi
+#include <cstring>                      // for strncmp, memcpy, strcmp, strlen
+
+#include <QtCore/QByteArray>            // for QByteArray
+#include <QtCore/QString>               // for QString, operator+
+#include <QtCore/QXmlStreamAttributes>  // for QXmlStreamAttributes
+#include <QtCore/QtGlobal>              // for qPrintable
 
 #include "defs.h"
-#include "jeeps/gpsmath.h"
-#include "xmlgeneric.h"
+#include "gbfile.h"                     // for gbfgetdbl, gbfgetint32, gbfputint32, gbfgetint16, gbfputdbl, gbfputc, gbfread, gbfseek, gbfgetc, gbfile, gbfclose, gbfungetc, gbfeof, gbfputs, gbfwrite, gbfopen_le, gbfgetuint32, gbfputuint16, gbfputuint32
+#include "jeeps/gpsmath.h"              // for GPS_Lookup_Datum_Index, GPS_Math_Known_Datum_To_WGS84_C, GPS_Math_NGENToAiry1830LatLon
+#include "xmlgeneric.h"                 // for cb_cdata, xg_callback, xg_string, xml_deinit, xml_init, cb_end, cb_start, xg_cb_type, xml_read, xml_readstring, xg_tag_mapping
+
 
 #define MYNAME "dmtlog"
 
@@ -711,8 +721,7 @@ write_header(const route_head* trk)
 
   int count = 0;
   if (trk != nullptr) {
-    queue* curr, *prev;
-    QUEUE_FOR_EACH(&trk->waypoint_list, curr, prev) count++;
+    count = trk->waypoint_list.count();
   }
   if (!trk || trk->rte_name.isEmpty()) {
     write_str("Name", fout);
index 6d62688c8d2605c731a26c0e245aaaa3cf76d554..e5b5dee55c3b312c361bb3b789fbab1bfdf2ae56 100644 (file)
     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA
 
  */
+
+#include <cstdio>               // for sprintf
+#include <cstdlib>              // for qsort
+#include <cstring>              // for memset, strncpy
+
+#include <QtCore/QDateTime>     // for QDateTime
+#include <QtCore/QtGlobal>      // for foreach
+
 #include "defs.h"
-#include "duplicate.h"
 #include "filterdefs.h"
-#include <cstdio>
-#include <cstdlib> // qsort
+#include "duplicate.h"
+#include "src/core/datetime.h"  // for DateTime
+
 
 #if FILTERS_ENABLED
 
@@ -145,19 +153,13 @@ void DuplicateFilter::process()
   Waypoint* delwpt = nullptr;
 
   int ct = waypt_count();
-  queue* elem, *tmp;
 
   wpt_ptr* htable = (wpt_ptr*) xmalloc(ct * sizeof(*htable));
   wpt_ptr* bh = htable;
 
   int i = 0;
-#if NEWQ
-  foreach (Waypoint* waypointp, waypt_list) {
+  foreach (Waypoint* waypointp, *global_waypoint_list) {
     bh->wpt = waypointp;
-#else
-  QUEUE_FOR_EACH(&waypt_head, elem, tmp) {
-    bh->wpt = reinterpret_cast<Waypoint *>(elem);
-#endif
     bh->index = i;
     i ++;
     bh ++;
index 389b1fccd3d4636536f96b5dedafb50cbc27f900..fae64507c4feaffbd9cf58b2167401457821777e 100644 (file)
 #ifndef FILTERDEFS_H_INCLUDED_
 #define FILTERDEFS_H_INCLUDED_
 
-#if NEWQ
-#include <QtCore/QList>
-extern QList<Waypoint*> waypt_list;
-#else
-#include "queue.h"
-extern queue waypt_head;
-#endif
+#include "defs.h"
 #include "filter.h"
 
+extern WaypointList* global_waypoint_list;
+
 typedef void (*filter_init)();
 typedef void (*filter_process)();
 typedef void (*filter_deinit)();
index b393706cfc5048590eeb76f076c1e8d8d47ff0ec..e37c948884787ba063a8cfdda1b1da3beb1f746c 100644 (file)
--- a/garmin.cc
+++ b/garmin.cc
 
  */
 
-#include <cctype>
-#include <climits>
-#include <cmath>
-#include <cstdlib>
+#include <cctype>               // for isalpha, toupper
+#include <climits>              // for INT_MAX
+#include <cmath>                // for atan2, floor, sqrt
+#include <csetjmp>              // for setjmp
+#include <cstdio>               // for fprintf, fflush, snprintf, sprintf
+#include <cstdlib>              // for atoi, strtol
+#include <cstring>              // for memcpy, strlen, strncpy, strchr
+#include <ctime>                // for time_t
+
+#include <QtCore/QByteArray>    // for QByteArray
+#include <QtCore/QChar>         // for QChar
+#include <QtCore/QString>       // for QString
+#include <QtCore/Qt>            // for CaseInsensitive
+#include <QtCore/QtGlobal>      // for qPrintable, foreach
 
-#include "cet_util.h"
 #include "defs.h"
-#include "garmin_device_xml.h"
-#include "garmin_fs.h"
-#include "garmin_tables.h"
-#include "grtcirc.h"
+#include "cet_util.h"           // for cet_convert_init, cet_cs_vec_utf8
+#include "garmin_device_xml.h"  // for gdx_get_info, gdx_info, gdx_file, gdx_jmp_buf
+#include "garmin_fs.h"          // for garmin_fs_garmin_after_read, garmin_fs_garmin_before_write
+#include "garmin_tables.h"      // for gt_find_icon_number_from_desc, PCX, gt_find_desc_from_icon_number
+#include "grtcirc.h"            // for DEG
 #include "jeeps/gps.h"
 #include "jeeps/gpsserial.h"
+#include "src/core/datetime.h"  // for DateTime
 
 #define MYNAME "GARMIN"
 static const char* portname;
@@ -910,12 +921,7 @@ waypoint_prepare()
 {
   int i;
   int n = waypt_count();
-#if NEWQ
-  extern QList<Waypoint*> waypt_list;
-#else
-  queue* elem, *tmp;
-  extern queue waypt_head;
-#endif
+  extern WaypointList* global_waypoint_list;
   int icon;
 
   tx_waylist = (struct GPS_SWay**) xcalloc(n,sizeof(*tx_waylist));
@@ -926,13 +932,8 @@ waypoint_prepare()
 
   i = 0;
 
-#if NEWQ
   // Iterate with waypt_disp_all?
-  foreach(Waypoint* wpt, waypt_list) {
-#else
-  QUEUE_FOR_EACH(&waypt_head, elem, tmp) {
-    Waypoint* wpt = reinterpret_cast<Waypoint *>(elem);
-#endif
+  foreach(Waypoint* wpt, *global_waypoint_list) {
     char obuf[256];
 
     QString src;
diff --git a/gdb.cc b/gdb.cc
index 6b9bc00900718396035c12a52d9bfab97758a3e3..795b398194741de18f0c25bcc2e857d7ad50b1fb 100644 (file)
--- a/gdb.cc
+++ b/gdb.cc
@@ -26,6 +26,7 @@
 #include <cstdlib>                 // for atoi, strtol, NULL
 #include <cstring>                 // for memset, strcmp, strstr, strchr, strlen, strncpy
 #include <ctime>                   // for strftime
+#include <iterator>                // for next
 
 #include <QtCore/QByteArray>       // for QByteArray
 #include <QtCore/QList>            // for QList
@@ -41,7 +42,6 @@
 #include "gbfile.h"                // for gbfputint32, gbfgetint32, gbfread, gbfwrite, gbfgetc, gbfputc, gbfgetdbl, gbfgetcstr, gbfile, gbfclose, gbfputcstr, gbfcopyfrom, gbfrewind, gbfseek, gbftell, gbfopen_le, gbfgetcstr_old, gbfgetint16, gbfputdbl, gbfputint16
 #include "grtcirc.h"               // for RAD, gcdist, radtometers
 #include "jeeps/gpsmath.h"         // for GPS_Math_Deg_To_Semi, GPS_Math_Semi_To_Deg
-#include "queue.h"                 // for queue, QUEUE_FOR_EACH
 #include "src/core/datetime.h"     // for DateTime
 
 
@@ -1396,10 +1396,8 @@ write_waypoint(
 static void
 route_compute_bounds(const route_head* rte, bounds* bounds)
 {
-  queue* elem, *tmp;
   waypt_init_bounds(bounds);
-  QUEUE_FOR_EACH((queue*)&rte->waypoint_list, elem, tmp) {
-    Waypoint* wpt = reinterpret_cast<Waypoint *>(elem);
+  foreach (Waypoint* wpt, rte->waypoint_list) {
     gdb_check_waypt(wpt);
     waypt_add_to_bounds(bounds, wpt);
   }
@@ -1425,7 +1423,6 @@ static void
 write_route(const route_head* rte, const QString& rte_name)
 {
   bounds bounds;
-  queue* elem, *tmp;
   char zbuf[32], ffbuf[32];
 
   memset(zbuf, 0, sizeof(zbuf));
@@ -1442,10 +1439,13 @@ write_route(const route_head* rte, const QString& rte_name)
 
   int index = 0;
 
-  QUEUE_FOR_EACH((queue*)&rte->waypoint_list, elem, tmp) {
+  for (auto it =rte->waypoint_list.cbegin(); it != rte->waypoint_list.cend(); ++it) {
 
-    Waypoint* wpt = reinterpret_cast<Waypoint *>(elem);
-    Waypoint* next = reinterpret_cast<Waypoint *>(tmp);
+    Waypoint* wpt = *it;
+    Waypoint* next = nullptr;
+    if (index < points) {
+      next = *std::next(it);
+    }
 
     index++;
     rtept_ct++;        /* increase informational number of written route points */
@@ -1543,7 +1543,6 @@ write_route(const route_head* rte, const QString& rte_name)
 static void
 write_track(const route_head* trk, const QString& trk_name)
 {
-  queue* elem, *tmp;
   int points = ELEMENTS(trk);
 
   FWRITE_CSTR(trk_name);
@@ -1553,8 +1552,7 @@ write_track(const route_head* trk, const QString& trk_name)
 
   FWRITE_i32(points);  /* total number of waypoints in waypoint list */
 
-  QUEUE_FOR_EACH((queue*)&trk->waypoint_list, elem, tmp) {
-    Waypoint* wpt = reinterpret_cast<Waypoint *>(elem);
+  foreach (const Waypoint* wpt, trk->waypoint_list) {
 
     trkpt_ct++;        /* increase informational number of written route points */
 
index 0806a41b0c136cd7c81889f82d1e7ca857f58cf1..ed5f1735cce5aeaf30c20f1e5e6f82aec155dc53 100644 (file)
 
  */
 
-#include <cctype>
-#include <cmath>
-#include <cstdio>
-#include <ctime>
+#include <cmath>                   // for fabs, floor, lround
+#include <cstdio>                  // for sscanf
+#include <cstring>                 // for memset, strncmp
+#include <cstdint>                 // for int16_t
+#include <ctime>                   // for gmtime
+
+#include <QtCore/QString>          // for QString
+#include <QtCore/QTime>            // for QTime
+#include <QtCore/QtGlobal>         // for foreach
 
 #include "defs.h"
-#include "grtcirc.h"
-#include "jeeps/gpsmath.h"
+#include "gbfile.h"                // for gbfputint16, gbfclose, gbfopen, gbfputflt, gbfgetc, gbfputcstr, gbfputdbl, gbfread, gbfile
+#include "grtcirc.h"               // for heading_true_degrees
+#include "src/core/datetime.h"     // for DateTime
+
+
 
 #define MYNAME "ggv_log"
 
@@ -196,13 +204,11 @@ ggv_log_wr_deinit()
 static void
 ggv_log_track_head_cb(const route_head* trk)
 {
-  queue* elem, *tmp;
-  Waypoint* prev = nullptr;
+  const Waypoint* prev = nullptr;
 
-  QUEUE_FOR_EACH((queue*)&trk->waypoint_list, elem, tmp) {
+  foreach (const Waypoint* wpt, trk->waypoint_list) {
     double  course = 0, speed = 0;
     struct tm tm;
-    Waypoint* wpt = reinterpret_cast<Waypoint *>(elem);
     double secs = 0;
 
     int latint = wpt->latitude;
index 9fbcd8b0f9af1eebc0bc902b8dad7f58619f6811..aa2aa11e0dc2f3cc1563842fc55fb044a5798b1c 100644 (file)
 
  */
 
+#include <cmath>            // for sin, cos, acos
+#include <cstdio>           // for snprintf
+
+#include <QtCore/QString>   // for QString
+#include <QtCore/QtGlobal>  // for foreach
+
 #include "defs.h"
-#include "grtcirc.h"
-#include "inifile.h"
+#include "gbfile.h"         // for gbfprintf, gbfclose, gbfopen, gbfile
+#include "grtcirc.h"        // for RAD, gcdist, DEG
+#include "inifile.h"        // for inifile_readstr, inifile_readint_def, inifile_done, inifile_init, inifile_readint, inifile_t
 
-#include <QtCore/QString>
-#include <cmath>
-#include <cstdio>
-#include <cstdlib>
 
 #define MYNAME "ggv_ovl"
 
@@ -268,7 +271,6 @@ waypt_disp_cb(const Waypoint* wpt)
 static void
 track_disp_cb(const route_head* trk)
 {
-  queue* elem, *tmp;
   int waypt_ct = trk->rte_waypt_ct;
 
   if (waypt_ct <= 0) {
@@ -283,9 +285,7 @@ track_disp_cb(const route_head* trk)
 
   int i = 0;
 
-  QUEUE_FOR_EACH(&(trk->waypoint_list), elem, tmp) {
-
-    Waypoint* wpt = reinterpret_cast<Waypoint *>(elem);
+  foreach (const Waypoint* wpt, trk->waypoint_list) {
 
     gbfprintf(fout, "XKoord%d=%0.8f\n", i, wpt->longitude);
     gbfprintf(fout, "YKoord%d=%0.8f\n", i, wpt->latitude);
@@ -299,7 +299,6 @@ track_disp_cb(const route_head* trk)
 static void
 route_disp_cb(const route_head* rte)
 {
-  queue* elem, *tmp;
   int waypt_ct = rte->rte_waypt_ct;
 
   if (waypt_ct <= 0) {
@@ -311,11 +310,9 @@ route_disp_cb(const route_head* rte)
   color = OVL_COLOR_RED;
 
   int i = 0;
-  Waypoint* prev = nullptr;
-
-  QUEUE_FOR_EACH(&(rte->waypoint_list), elem, tmp) {
+  const Waypoint* prev = nullptr;
 
-    Waypoint* wpt = reinterpret_cast<Waypoint *>(elem);
+  foreach (const Waypoint* wpt, rte->waypoint_list) {
 
     if (prev != nullptr) {
       draw_symbol_basics(OVL_SYMBOL_TRIANGLE, 1, (OVL_COLOR_TYP)9 /* color */, prev);
diff --git a/gpx.cc b/gpx.cc
index 41d1d3e4c2695454a3241a0916580c02b3eb4cb7..52d09d0f279db1d68b97c634168759ee5011f578 100644 (file)
--- a/gpx.cc
+++ b/gpx.cc
 
  */
 
+#include <cmath>                                   // for lround
+#include <cstdio>                                  // for sscanf
+#include <cstdlib>                                 // for atoi, strtod
+#include <cstring>                                 // for strchr, strncpy
+
+#include <QtCore/QDate>                            // for QDate
+#include <QtCore/QDateTime>                        // for QDateTime
+#include <QtCore/QHash>                            // for QHash
+#include <QtCore/QIODevice>                        // for QIODevice, operator|, QIODevice::ReadOnly, QIODevice::Text, QIODevice::WriteOnly
+#include <QtCore/QLatin1String>                    // for QLatin1String
+#include <QtCore/QStaticStringData>                // for QStaticStringData
+#include <QtCore/QString>                          // for QString, QStringLiteral, operator+, operator==
+#include <QtCore/QStringList>                      // for QStringList
+#include <QtCore/QStringRef>                       // for QStringRef
+#include <QtCore/QTime>                            // for QTime
+#include <QtCore/QVector>                          // for QVector
+#include <QtCore/QXmlStreamAttribute>              // for QXmlStreamAttribute
+#include <QtCore/QXmlStreamAttributes>             // for QXmlStreamAttributes
+#include <QtCore/QXmlStreamNamespaceDeclaration>   // for QXmlStreamNamespaceDeclaration
+#include <QtCore/QXmlStreamNamespaceDeclarations>  // for QXmlStreamNamespaceDeclarations
+#include <QtCore/QXmlStreamReader>                 // for QXmlStreamReader, QXmlStreamReader::Characters, QXmlStreamReader::EndDocument, QXmlStreamReader::EndElement, QXmlStreamReader::Invalid, QXmlStreamReader::StartElement
+#include <QtCore/Qt>                               // for CaseInsensitive, UTC
+#include <QtCore/QtGlobal>                         // for qAsConst, QAddConst<>::Type
+
 #include "defs.h"
 #include "garmin_fs.h"
 #include "garmin_tables.h"
 #include "src/core/xmlstreamwriter.h"
 #include "src/core/xmltag.h"
 
-#include <QtCore/QDateTime>            // for QDateTime, QDate, QTime
-#include <QtCore/QHash>                // for QHash
-#include <QtCore/QList>                // for QList
-#include <QtCore/QString>              // for QString, QStringLiteral, QStringRef, QStaticStringData, QLatin1String, operator+
-#include <QtCore/QStringList>          // for QStringList
-#include <QtCore/QXmlStreamAttributes> // for QXmlStreamAttributes
-#include <QtCore/QXmlStreamNamespaceDeclarations> // for QXmlStreamNamespaceDeclarations
-#include <QtCore/QXmlStreamReader>     // for QXmlStreamReader, QXmlStreamReader::TokenType::Characters, QXmlStreamReader::TokenType::EndDocument, QXmlStreamReader::TokenType::EndElement, QXmlStreamReader::TokenType::Invalid, QXmlStreamReader::TokenType::StartElement
-#include <QtCore/QtGlobal>             // for qAsConst
-
-#include <cmath>                       // for lround
-#include <cstdio>                      // for sscanf
-#include <cstdlib>                     // for atoi, strtod
-#include <cstring>                     // for strchr
-
 
 static QXmlStreamReader* reader;
 static xml_tag* cur_tag;
@@ -1827,7 +1836,7 @@ gpx_track_hdr(const route_head* rte)
 static void
 gpx_track_disp(const Waypoint* waypointp)
 {
-  bool first_in_trk = waypointp->Q.prev == &current_trk_head->waypoint_list;
+  bool first_in_trk = waypointp == current_trk_head->waypoint_list.front();
 
   if (waypointp->wpt_flags.new_trkseg) {
     if (!first_in_trk) {
@@ -1864,7 +1873,7 @@ gpx_track_disp(const Waypoint* waypointp)
 static void
 gpx_track_tlr(const route_head*)
 {
-  if (!QUEUE_EMPTY(&current_trk_head->waypoint_list)) {
+  if (!current_trk_head->waypoint_list.empty()) {
     writer->writeEndElement();
   }
 
diff --git a/igc.cc b/igc.cc
index 2bccfaf51ba33ff4911b200200a20e7b7dc10021..eefed682ab3add7f5f203749e97d6d5a4028dc10 100644 (file)
--- a/igc.cc
+++ b/igc.cc
  * 59 Temple Place - Suite 330, Boston, MA 02111 USA
  */
 
+#include <cmath>                     // for fabs, lround
+#include <cstdio>                    // for sscanf, snprintf, fputs, printf, stdout, putchar, size_t
+#include <cstdlib>                   // for labs, ldiv, ldiv_t, abs
+#include <cstring>                   // for strcmp, strlen, strtok, strcat, strchr, strcpy, strncat
+#include <ctime>                     // for gmtime, ctime
+#include <iterator>                  // for reverse_iterator, operator==, prev, next
+
+#include <QtCore/QByteArray>         // for QByteArray
+#include <QtCore/QList>              // for QList<>::const_iterator
+#include <QtCore/QStaticStringData>  // for QStaticStringData
+#include <QtCore/QString>            // for QString, operator+, QStringLiteral
+#include <QtCore/QtGlobal>           // for foreach, qPrintable
+
 #include "defs.h"
-#include "cet_util.h"
-#include <cerrno>
-#include <cmath>
-#include <cstdio>
-#include <cstdlib>
+#include "cet_util.h"                // for cet_convert_init
+#include "gbfile.h"                  // for gbfprintf, gbfclose, gbfopen, gbfputs, gbfgetstr, gbfile
+#include "src/core/datetime.h"       // for DateTime
+#include "src/core/optional.h"       // for optional
+
 
 static gbfile* file_in, *file_out;
 static char manufacturer[4];
@@ -590,7 +603,7 @@ static void wr_header()
   }
   // Date in header record is that of the first fix record
   date = !track ? current_time().toTime_t() :
-         (reinterpret_cast<Waypoint *>QUEUE_FIRST(&track->waypoint_list))->GetCreationTime().toTime_t();
+         track->waypoint_list.front()->GetCreationTime().toTime_t();
 
   if (nullptr == (tm = gmtime(&date))) {
     fatal(MYNAME ": Bad track timestamp\n");
@@ -662,11 +675,11 @@ static void wr_task_hdr(const route_head* rte)
   }
   // See if the takeoff and landing waypoints are there or if we need to
   // generate them.
-  const Waypoint* wpt = reinterpret_cast<Waypoint *>QUEUE_LAST(&rte->waypoint_list);
+  const Waypoint* wpt = rte->waypoint_list.back();
   if (wpt->shortname.startsWith("LANDING")) {
     num_tps--;
   }
-  wpt = reinterpret_cast<Waypoint *>QUEUE_FIRST(&rte->waypoint_list);
+  wpt = rte->waypoint_list.front();
   if (wpt->shortname.startsWith("TAKEOFF")) {
     have_takeoff = 1;
     num_tps--;
@@ -704,7 +717,7 @@ static void wr_task_wpt(const Waypoint* wpt)
 static void wr_task_tlr(const route_head* rte)
 {
   // If the landing waypoint is not supplied we need to generate it.
-  const Waypoint* wpt = reinterpret_cast<Waypoint *>QUEUE_LAST(&rte->waypoint_list);
+  const Waypoint* wpt = rte->waypoint_list.back();
   QString sn = wpt->shortname;
 //  if (!wpt->shortname || strncmp(wpt->shortname, "LANDIN", 6) != 0) {
   if (sn.isEmpty() || !sn.startsWith("LANDIN")) {
@@ -757,45 +770,45 @@ static int correlate_tracks(const route_head* pres_track, const route_head* gnss
 
   // Deduce the landing time from the pressure altitude track based on
   // when we last descended to within 10m of the final track altitude.
-  const queue* elem = QUEUE_LAST(&pres_track->waypoint_list);
-  double last_alt = (reinterpret_cast<const Waypoint *>(elem))->altitude;
+  WaypointList::const_reverse_iterator wpt_rit = pres_track->waypoint_list.crbegin();
+  double last_alt = (*wpt_rit)->altitude;
   do {
-    elem = elem->prev;
-    if (&pres_track->waypoint_list == elem) {
+    ++wpt_rit;
+    if (pres_track->waypoint_list.crend() == wpt_rit) {
       // No track left
       return 0;
     }
-    alt_diff = last_alt - (reinterpret_cast<const Waypoint *>(elem))->altitude;
+    alt_diff = last_alt - (*wpt_rit)->altitude;
     if (alt_diff > 10.0) {
       // Last part of track was ascending
       return 0;
     }
   } while (alt_diff > -10.0);
-  pres_time = (reinterpret_cast<Waypoint *>(elem->next))->GetCreationTime().toTime_t();
+  pres_time = (*std::prev(wpt_rit))->GetCreationTime().toTime_t();
   if (global_opts.debug_level >= 1) {
     printf(MYNAME ": pressure landing time %s", ctime(&pres_time));
   }
+
   // Deduce the landing time from the GNSS altitude track based on
   // when the groundspeed last dropped below a certain level.
-  elem = QUEUE_LAST(&gnss_track->waypoint_list);
-  last_alt = (reinterpret_cast<const Waypoint *>(elem))->altitude;
+  wpt_rit = gnss_track->waypoint_list.crbegin();
   do {
-    const Waypoint* wpt = reinterpret_cast<const Waypoint *>(elem);
-    elem = elem->prev;
-    if (&gnss_track->waypoint_list == elem) {
+    const Waypoint* wpt = *wpt_rit;
+    ++wpt_rit;
+    if (gnss_track->waypoint_list.crend() == wpt_rit) {
       // No track left
       return 0;
     }
     // Get a crude indication of groundspeed from the change in lat/lon
-    time_diff = wpt->GetCreationTime().toTime_t() - (reinterpret_cast<const Waypoint *>(elem))->GetCreationTime().toTime_t();
+    time_diff = wpt->GetCreationTime().toTime_t() - (*wpt_rit)->GetCreationTime().toTime_t();
     speed = !time_diff ? 0 :
-            (fabs(wpt->latitude - (reinterpret_cast<const Waypoint *>(elem))->latitude) +
-             fabs(wpt->longitude - (reinterpret_cast<const Waypoint *>(elem))->longitude)) / time_diff;
+            (fabs(wpt->latitude - (*wpt_rit)->latitude) +
+             fabs(wpt->longitude - (*wpt_rit)->longitude)) / time_diff;
     if (global_opts.debug_level >= 2) {
       printf(MYNAME ": speed=%f\n", speed);
     }
   } while (speed < 0.00003);
-  gnss_time = (reinterpret_cast<Waypoint *>(elem->next))->GetCreationTime().toTime_t();
+  gnss_time = (*std::prev(wpt_rit))->GetCreationTime().toTime_t();
   if (global_opts.debug_level >= 1) {
     printf(MYNAME ": gnss landing time %s", ctime(&gnss_time));
   }
@@ -814,43 +827,42 @@ static int correlate_tracks(const route_head* pres_track, const route_head* gnss
  */
 static double interpolate_alt(const route_head* track, time_t time)
 {
-  static const queue* prev_elem = nullptr;
-  static const queue* curr_elem = nullptr;
+  static gpsbabel_optional::optional<WaypointList::const_iterator> prev_wpt;
+  static gpsbabel_optional::optional<WaypointList::const_iterator> curr_wpt;
   int time_diff;
 
   // Start search at the beginning of the track
-  if (!prev_elem) {
-    curr_elem = prev_elem = QUEUE_FIRST(&track->waypoint_list);
+  if (!prev_wpt.has_value()) {
+    prev_wpt = track->waypoint_list.cbegin();
+    curr_wpt = track->waypoint_list.cbegin();
   }
   // Find the track points either side of the requested time
-  while ((reinterpret_cast<const Waypoint *>(curr_elem))->GetCreationTime().toTime_t() < time) {
-    if (QUEUE_LAST(&track->waypoint_list) == curr_elem) {
-      // Requested time later than all track points, we can't interpolate
-      return unknown_alt;
-    }
-    prev_elem = curr_elem;
-    curr_elem = QUEUE_NEXT(prev_elem);
+  while ((track->waypoint_list.cend() != curr_wpt.value()) &&
+         ((*curr_wpt.value())->GetCreationTime().toTime_t() < time)) {
+    prev_wpt = curr_wpt.value();
+    curr_wpt = std::next(prev_wpt.value());
+  }
+  if (track->waypoint_list.cend() == curr_wpt.value()) {
+    // Requested time later than all track points, we can't interpolate
+    return unknown_alt;
   }
 
-  const Waypoint* prev_wpt = reinterpret_cast<const Waypoint *>(prev_elem);
-  const Waypoint* curr_wpt = reinterpret_cast<const Waypoint *>(curr_elem);
-
-  if (QUEUE_FIRST(&track->waypoint_list) == curr_elem) {
-    if (curr_wpt->GetCreationTime().toTime_t() == time) {
+  if (track->waypoint_list.cbegin() == curr_wpt.value()) {
+    if ((*curr_wpt.value())->GetCreationTime().toTime_t() == time) {
       // First point's creation time is an exact match so use it's altitude
-      return curr_wpt->altitude;
+      return (*curr_wpt.value())->altitude;
     } else {
       // Requested time is prior to any track points, we can't interpolate
       return unknown_alt;
     }
   }
   // Interpolate
-  if (0 == (time_diff = curr_wpt->GetCreationTime().toTime_t() - prev_wpt->GetCreationTime().toTime_t())) {
+  if (0 == (time_diff = (*curr_wpt.value())->GetCreationTime().toTime_t() - (*prev_wpt.value())->GetCreationTime().toTime_t())) {
     // Avoid divide by zero
-    return curr_wpt->altitude;
+    return (*curr_wpt.value())->altitude;
   }
-  double alt_diff = curr_wpt->altitude - prev_wpt->altitude;
-  return prev_wpt->altitude + (alt_diff / time_diff) * (time - prev_wpt->GetCreationTime().toTime_t());
+  double alt_diff = (*curr_wpt.value())->altitude - (*prev_wpt.value())->altitude;
+  return (*prev_wpt.value())->altitude + (alt_diff / time_diff) * (time - (*prev_wpt.value())->GetCreationTime().toTime_t());
 }
 
 /*
@@ -881,11 +893,7 @@ static void wr_track()
       printf(MYNAME ": adjusting time by %ds\n", time_adj);
     }
     // Iterate through waypoints in both tracks simultaneously
-    const queue* elem;
-    const queue* tmp;
-    QUEUE_FOR_EACH(&gnss_track->waypoint_list, elem, tmp) {
-      // FIXME(NEW_Q): the excessive casting of the iterators is gross. Rethink.
-      const Waypoint* wpt = reinterpret_cast<const Waypoint*>(elem);
+    foreach (const Waypoint* wpt, gnss_track->waypoint_list) {
       double pres_alt = interpolate_alt(pres_track, wpt->GetCreationTime().toTime_t() + time_adj);
       wr_fix_record(wpt, pres_alt, wpt->altitude);
     }
@@ -893,19 +901,13 @@ static void wr_track()
     if (pres_track) {
       // Only the pressure altitude track was found so generate fix
       // records from it alone.
-      const queue* elem;
-      const queue* tmp;
-      QUEUE_FOR_EACH(&pres_track->waypoint_list, elem, tmp) {
-        const Waypoint* wpt = reinterpret_cast<const Waypoint*>(elem);
+      foreach (const Waypoint* wpt, pres_track->waypoint_list) {
         wr_fix_record(wpt, wpt->altitude, unknown_alt);
       }
     } else if (gnss_track) {
       // Only the GNSS altitude track was found so generate fix
       // records from it alone.
-      const queue* elem;
-      const queue* tmp;
-      QUEUE_FOR_EACH(&gnss_track->waypoint_list, elem, tmp) {
-        const Waypoint* wpt = reinterpret_cast<const Waypoint*>(elem);
+      foreach (const Waypoint* wpt, gnss_track->waypoint_list) {
         wr_fix_record(wpt, unknown_alt, wpt->altitude);
       }
     } else {
index fa8933fc8c4578e9838b0fb124f26d31f4647fd7..a46fdf1846a379a88ba380354d08db6549491851 100644 (file)
 
  */
 
+#include <cstdlib>              // for atoi, strtod
+
+#include <QtCore/QString>       // for QString
+#include <QtCore/QtGlobal>      // for qAsConst, QAddConst<>::Type, foreach
+
 #include "defs.h"
 #include "filterdefs.h"
-#include "grtcirc.h"
 #include "interpolate.h"
-#include <cstdlib>
+#include "grtcirc.h"            // for linepart, RAD, gcdist, radtomiles
+#include "src/core/datetime.h"  // for DateTime
+
 
 #if FILTERS_ENABLED
 #define MYNAME "Interpolate filter"
@@ -31,7 +37,6 @@
 void InterpolateFilter::process()
 {
   RouteList* backuproute = nullptr;
-  queue* elem2, *tmp2;
   double lat1 = 0, lon1 = 0;
   double altitude1 = unknown_alt;
   unsigned int time1 = 0;
@@ -49,8 +54,7 @@ void InterpolateFilter::process()
     fatal(MYNAME ": Found no routes or tracks to operate on.\n");
   }
 
-  for (auto it = backuproute->cbegin(); it != backuproute->cend(); ++it) {
-    auto rte_old = reinterpret_cast<const route_head*>(*it);
+  for (const auto* rte_old : qAsConst(*backuproute)) {
 
     route_head* rte_new = route_head_alloc();
     rte_new->rte_name = rte_old->rte_name;
@@ -63,8 +67,7 @@ void InterpolateFilter::process()
       track_add_head(rte_new);
     }
     bool first = true;
-    QUEUE_FOR_EACH(&rte_old->waypoint_list, elem2, tmp2) {
-      Waypoint* wpt = reinterpret_cast<Waypoint *>(elem2);
+    foreach (const Waypoint* wpt, rte_old->waypoint_list) {
       if (first) {
         first = false;
       } else {
diff --git a/kml.cc b/kml.cc
index 11c09db5930bbea68914e818d0541663cecb43db..45217908d16894b435be4b76f2697c602982bb2e 100644 (file)
--- a/kml.cc
+++ b/kml.cc
 # include <windows.h>
 #endif
 
-#include "defs.h"
-#include "grtcirc.h"
-#include "queue.h"
-#include "src/core/datetime.h"
-#include "src/core/file.h"
-#include "src/core/xmlstreamwriter.h"
-#include "src/core/xmltag.h"
-#include "xmlgeneric.h"
-#include <QtCore/QXmlStreamAttributes> // for QXmlStreamAttributes
+#include <cctype>                      // for tolower, toupper
+#include <cmath>                       // for fabs
+#include <cstdio>                      // for sscanf, printf
+#include <cstdlib>                     // for atoi, atol, atof
+#include <cstring>                     // for strcmp
+#include <tuple>                       // for tuple, make_tuple, tie
+
+#include <QtCore/QByteArray>           // for QByteArray
+#include <QtCore/QChar>                // for QChar
+#include <QtCore/QDate>                // for QDate
 #include <QtCore/QDateTime>            // for QDateTime
 #include <QtCore/QFile>                // for QFile
+#include <QtCore/QIODevice>            // for operator|, QIODevice, QIODevice::Text, QIODevice::WriteOnly
 #include <QtCore/QList>                // for QList
-#include <QtCore/QString>              // for QString, QStringLiteral, QStat...
-#include <QtCore/QtGlobal>             // for qint64, qPrintable
-#include <cctype>
-#include <cmath>
-#include <cstdio>
-#include <cstdlib>
-#include <cstring>
-#include <tuple>
+#include <QtCore/QStaticStringData>    // for QStaticStringData
+#include <QtCore/QString>              // for QString, QStringLiteral, operator+, operator!=
+#include <QtCore/QXmlStreamAttributes> // for QXmlStreamAttributes
+#include <QtCore/Qt>                   // for ISODate
+#include <QtCore/QtGlobal>             // for foreach, qint64, qPrintable
+
+#include "defs.h"
+#include "grtcirc.h"                    // for RAD, gcdist, radtometers
+#include "src/core/datetime.h"          // for DateTime
+#include "src/core/file.h"              // for File
+#include "src/core/optional.h"          // for optional
+#include "src/core/xmlstreamwriter.h"   // for XmlStreamWriter
+#include "src/core/xmltag.h"            // for xml_findfirst, xml_tag, fs_xml, xml_attribute, xml_findnext
+#include "xmlgeneric.h"                 // for cb_cdata, cb_end, cb_start, xg_callback, xg_string, xg_cb_type, xml_deinit, xml_ignore_tags, xml_init, xml_read, xg_tag_mapping
+
 
 // options
 static char* opt_deficon = nullptr;
@@ -443,10 +452,7 @@ void trk_coord(xg_string args, const QXmlStreamAttributes*)
     if (trk_head->rte_waypt_ct > 0) {
       qint64 timespan_ms = wpt_timespan_begin.msecsTo(wpt_timespan_end);
       qint64 ms_per_waypoint = timespan_ms / trk_head->rte_waypt_ct;
-      queue* curr_elem;
-      queue* tmp_elem;
-      QUEUE_FOR_EACH(&trk_head->waypoint_list, curr_elem, tmp_elem) {
-        trkpt = reinterpret_cast<Waypoint*>(curr_elem);
+      foreach (Waypoint* trkpt, trk_head->waypoint_list) {
         trkpt->SetCreationTime(wpt_timespan_begin);
         wpt_timespan_begin = wpt_timespan_begin.addMSecs(ms_per_waypoint);
       }
@@ -1095,11 +1101,9 @@ static void kml_output_tailer(const route_head* header)
   // Add a linestring for this track?
   if (export_lines && header->rte_waypt_ct > 0) {
     int needs_multigeometry = 0;
-    queue* elem, *tmp;
 
-    QUEUE_FOR_EACH(&header->waypoint_list, elem, tmp) {
-      Waypoint* tpt = reinterpret_cast<Waypoint*>(elem);
-      int first_in_trk = tpt->Q.prev == &header->waypoint_list;
+    foreach (const Waypoint* tpt, header->waypoint_list) {
+      int first_in_trk = tpt == header->waypoint_list.front();
       if (!first_in_trk && tpt->wpt_flags.new_trkseg) {
         needs_multigeometry = 1;
         break;
@@ -1134,9 +1138,8 @@ static void kml_output_tailer(const route_head* header)
       writer->writeStartElement(QStringLiteral("MultiGeometry"));
     }
 
-    QUEUE_FOR_EACH(&header->waypoint_list, elem, tmp) {
-      Waypoint* tpt = reinterpret_cast<Waypoint*>(elem);
-      int first_in_trk = tpt->Q.prev == &header->waypoint_list;
+    foreach (const Waypoint* tpt, header->waypoint_list) {
+      int first_in_trk = tpt == header->waypoint_list.front();
       if (tpt->wpt_flags.new_trkseg) {
         if (!first_in_trk) {
           writer->writeEndElement(); // Close coordinates tag
@@ -1717,13 +1720,10 @@ static void kml_mt_simple_array(const route_head* header,
                                 const char* name,
                                 wp_field member)
 {
-  queue* elem, *tmp;
   writer->writeStartElement(QStringLiteral("gx:SimpleArrayData"));
   writer->writeAttribute(QStringLiteral("name"), name);
 
-  QUEUE_FOR_EACH(&header->waypoint_list, elem, tmp) {
-
-    Waypoint* wpt = reinterpret_cast<Waypoint*>(elem);
+  foreach (const Waypoint* wpt, header->waypoint_list) {
 
     switch (member) {
     case fld_power:
@@ -1751,11 +1751,8 @@ static void kml_mt_simple_array(const route_head* header,
 // True if at least two points in the track have timestamps.
 static int track_has_time(const route_head* header)
 {
-  queue* elem, *tmp;
   int points_with_time = 0;
-  QUEUE_FOR_EACH(&header->waypoint_list, elem, tmp) {
-    Waypoint* tpt = reinterpret_cast<Waypoint*>(elem);
-
+  foreach (const Waypoint* tpt, header->waypoint_list) {
     if (tpt->GetCreationTime().isValid()) {
       points_with_time++;
       if (points_with_time >= 2) {
@@ -1769,10 +1766,8 @@ static int track_has_time(const route_head* header)
 // Simulate a track_disp_all callback sequence for a single track.
 static void write_as_linestring(const route_head* header)
 {
-  queue* elem, *tmp;
   kml_track_hdr(header);
-  QUEUE_FOR_EACH(&header->waypoint_list, elem, tmp) {
-    Waypoint* tpt = reinterpret_cast<Waypoint*>(elem);
+  foreach (const Waypoint* tpt, header->waypoint_list) {
     kml_track_disp(tpt);
   }
   kml_track_tlr(header);
@@ -1781,7 +1776,6 @@ static void write_as_linestring(const route_head* header)
 
 static void kml_mt_hdr(const route_head* header)
 {
-  queue* elem, *tmp;
   int has_cadence = 0;
   int has_depth = 0;
   int has_heartrate = 0;
@@ -1801,9 +1795,7 @@ static void kml_mt_hdr(const route_head* header)
   writer->writeStartElement(QStringLiteral("gx:Track"));
   kml_output_positioning(false);
 
-  QUEUE_FOR_EACH(&header->waypoint_list, elem, tmp) {
-    Waypoint* tpt = reinterpret_cast<Waypoint*>(elem);
-
+  foreach (const Waypoint* tpt, header->waypoint_list) {
     if (tpt->GetCreationTime().isValid()) {
       QString time_string = tpt->CreationTimeXML();
       writer->writeOptionalTextElement(QStringLiteral("when"), time_string);
@@ -1814,9 +1806,7 @@ static void kml_mt_hdr(const route_head* header)
   }
 
   // TODO: How to handle clamped, floating, extruded, etc.?
-  QUEUE_FOR_EACH(&header->waypoint_list, elem, tmp) {
-    Waypoint* tpt = reinterpret_cast<Waypoint*>(elem);
-
+  foreach (const Waypoint* tpt, header->waypoint_list) {
     if (kml_altitude_known(tpt)) {
       writer->writeTextElement(QStringLiteral("gx:coord"),
                                QString::number(tpt->longitude, 'f', precision) + QString(" ") +
@@ -2192,7 +2182,7 @@ kml_wr_position(Waypoint* wpt)
      track points if we've not moved a minimum distance from the
      beginning of our accumulated track. */
   {
-    Waypoint* newest_posn= reinterpret_cast<Waypoint*>QUEUE_LAST(&posn_trk_head->waypoint_list);
+    Waypoint* newest_posn= posn_trk_head->waypoint_list.back();
 
     if (radtometers(gcdist(RAD(wpt->latitude), RAD(wpt->longitude),
                            RAD(newest_posn->latitude), RAD(newest_posn->longitude))) > 50) {
@@ -2217,7 +2207,7 @@ kml_wr_position(Waypoint* wpt)
    */
   while (max_position_points &&
          (posn_trk_head->rte_waypt_ct >= max_position_points)) {
-    Waypoint* tonuke = reinterpret_cast<Waypoint*>QUEUE_FIRST(&posn_trk_head->waypoint_list);
+    Waypoint* tonuke = posn_trk_head->waypoint_list.front();
     track_del_wpt(posn_trk_head, tonuke);
   }
 
index 400b6435381f944b8d1fa023720e9f68a55a3d1c..e51acca31205cb91205ab9d3e3a7b99167a8426e 100644 (file)
 
 */
 
+#include <cmath>                 // for M_PI, atan, exp, log, tan
+#include <cstdio>                // for printf, snprintf, sprintf, SEEK_CUR
+#include <cstdlib>               // for atoi, abs
+#include <cstring>               // for strlen, strcmp
+#include <ctime>
+
+#include <QtCore/QByteArray>     // for QByteArray
+#include <QtCore/QDate>          // for QDate
+#include <QtCore/QDateTime>      // for QDateTime
+#include <QtCore/QLatin1String>  // for QLatin1String
+#include <QtCore/QString>        // for QString, operator+, operator==, operator!=
+#include <QtCore/QTextCodec>     // for QTextCodec
+#include <QtCore/QTime>          // for QTime
+#include <QtCore/Qt>             // for CaseInsensitive, UTC
+#include <QtCore/QtGlobal>       // for qPrintable, uint, foreach
 
 #include "defs.h"
-#include "src/core/datetime.h"
-#include <QtCore/QByteArray>
-#include <QtCore/QDate>
-#include <QtCore/QDateTime>
-#include <QtCore/QTime>
-#include <QtCore/QTextCodec>
-#include <QtCore/QDebug>
-#include <cmath>          // for lat/lon conversion 
-#include <cstdio>         // for gmtime
-#include <cstdlib>        // atoi
+#include "gbfile.h"              // for gbfgetint32, gbfputint32, gbfputint16, gbfgetc, gbfgetint16, gbfputc, gbfwrite, gbfeof, gbfgetflt, gbfclose, gbfgetdbl, gbfputdbl, gbfile, gbfputflt, gbfread, gbfseek, gbfopen_le
+#include "src/core/datetime.h"   // for DateTime
+
 
 typedef struct lowranceusr_icon_mapping {
   const int    value;
@@ -332,11 +340,7 @@ static int            waypt_table_sz;
 static int            waypt_table_ct;
 
 /* from waypt.c, we need to iterate over waypoints when extracting routes */
-#if NEWQ
-extern QList<Waypoint*> waypt_list;
-#else
-extern queue          waypt_head;
-#endif
+extern WaypointList* global_waypoint_list;
 
 static unsigned short waypt_out_count;
 static int            trail_count, lowrance_route_count;
@@ -470,18 +474,10 @@ register_waypt(const Waypoint* ref)
 static Waypoint*
 lowranceusr4_find_waypt(uint uid_unit, int uid_seq_low, int uid_seq_high)
 {
-#if !NEWQ
-  queue* elem, *tmp;
-#endif
   lowranceusr4_fsdata* fs = nullptr;
 
-#if NEWQ
   // Iterate with waypt_disp_all?
-  foreach (Waypoint* waypointp, waypt_list) {
-#else
-  QUEUE_FOR_EACH(&waypt_head, elem, tmp) {
-    Waypoint* waypointp = reinterpret_cast<Waypoint*>(elem);
-#endif
+  foreach (Waypoint* waypointp, *global_waypoint_list) {
     fs = (lowranceusr4_fsdata*) fs_chain_find(waypointp->fs, FS_LOWRANCEUSR4);
 
     if (fs && fs->uid_unit == uid_unit &&
@@ -501,18 +497,10 @@ lowranceusr4_find_waypt(uint uid_unit, int uid_seq_low, int uid_seq_high)
 static Waypoint*
 lowranceusr4_find_global_waypt(uint id1, uint id2, uint id3, uint id4)
 {
-#if !NEWQ
-  queue* elem, *tmp;
-#endif
   lowranceusr4_fsdata* fs = nullptr;
 
-#if NEWQ
   // Iterate with waypt_disp_all?
-  foreach (Waypoint* waypointp, waypt_list) {
-#else
-  QUEUE_FOR_EACH(&waypt_head, elem, tmp) {
-    Waypoint* waypointp = reinterpret_cast<Waypoint*>(elem);
-#endif
+  foreach (Waypoint* waypointp, *global_waypoint_list) {
     fs = (lowranceusr4_fsdata*) fs_chain_find(waypointp->fs, FS_LOWRANCEUSR4);
 
     if (fs && fs->UUID1 == id1 &&
index 58f1045e4845cb38cf21bd3a60d8120f92dd28bf..145aec092b937cc5ea57a0e2238a13e8fb005587 100644 (file)
@@ -47,7 +47,6 @@
 #include "gbfile.h"                // for gbfclose, gbfeof, gbfgets, gbfopen, gbfwrite, gbfile
 #include "gbser.h"                 // for gbser_deinit, gbser_init, gbser_is_serial, gbser_read_line, gbser_set_port, gbser_write, gbser_OK
 #include "magellan.h"              // for mm_meridian, mm_sportrak, icon_mapping_t, mm_gps315320, mm_unknown, mm_map330, mm_map410, pid_to_model_t, mm_gps310, m330_cleanse, mag_checksum, mag_find_descr_from_token, mag_find_token_from_descr, mag_rteparse, mag_trkparse
-#include "queue.h"                 // for queue, QUEUE_FOR_EACH
 #include "src/core/datetime.h"     // for DateTime
 
 
@@ -1073,7 +1072,7 @@ mag_rteparse(char* rtemsg)
 
   /*
    * This is the first component of a route.  Allocate a new
-   * queue head.
+   * head.
    */
   if (frag == 1) {
     mag_rte_head = new mag_rte_head_t;
@@ -1481,7 +1480,6 @@ and to replace the 2nd name with "<<>>", but I haven't seen one of those.
 static void
 mag_route_trl(const route_head* rte)
 {
-  queue* elem, *tmp;
   char obuff[256];
   char buff1[64], buff2[64];
   char* pbuff;
@@ -1497,8 +1495,7 @@ mag_route_trl(const route_head* rte)
   route_out_count++;
 
   int thisline = i = 0;
-  QUEUE_FOR_EACH(&rte->waypoint_list, elem, tmp) {
-    Waypoint* waypointp = reinterpret_cast<Waypoint *>(elem);
+  foreach (const Waypoint* waypointp, rte->waypoint_list) {
     i++;
 
     if (deficon) {
@@ -1515,7 +1512,7 @@ mag_route_trl(const route_head* rte)
     // Write name, icon tuple into alternating buff1/buff2 buffer.
     sprintf(pbuff, "%s,%s", CSTR(waypointp->shortname), CSTR(icon_token));
 
-    if ((tmp == &rte->waypoint_list) || ((i % 2) == 0)) {
+    if ((waypointp == rte->waypoint_list.back()) || ((i % 2) == 0)) {
       char expbuf[1024];
       thisline++;
       expbuf[0] = 0;
diff --git a/main.cc b/main.cc
index cbf1d36211500e7b9191d08cac3fd3ccae4d7d24..159098b297c243bca57462c525cbcec753e60459 100644 (file)
--- a/main.cc
+++ b/main.cc
@@ -49,7 +49,6 @@
 #include "filter.h"                 // for Filter
 #include "filterdefs.h"             // for disp_filter_vec, disp_filter_vecs, disp_filters, exit_filter_vecs, find_filter_vec, free_filter_vec, init_filter_vecs
 #include "inifile.h"                // for inifile_done, inifile_init
-#include "queue.h"                  // for queue
 #include "session.h"                // for start_session, session_exit, session_init
 #include "src/core/datetime.h"      // for DateTime
 #include "src/core/file.h"          // for File
@@ -228,9 +227,9 @@ run(const char* prog_name)
   const char* fvec_opts = nullptr;
   int opt_version = 0;
   bool did_something = false;
-  queue* wpt_head_bak;
-  RouteList* rte_head_bak, *trk_head_bak;
-  signed int wpt_ct_bak;
+  WaypointList* wpt_head_bak;
+  RouteList* rte_head_bak;
+  RouteList* trk_head_bak;
   bool lists_backedup;
   QStack<QargStackElement> qargs_stack;
 
@@ -350,7 +349,9 @@ run(const char* prog_name)
         cet_convert_init(ovecs->encode, ovecs->fixed_encode);
 
         lists_backedup = false;
-        rte_head_bak = trk_head_bak = nullptr;
+        wpt_head_bak = nullptr;
+        rte_head_bak = nullptr;
+        trk_head_bak = nullptr;
 
         ovecs->wr_init(ofname);
 
@@ -364,7 +365,7 @@ run(const char* prog_name)
           int saved_status = global_opts.verbose_status;
           global_opts.verbose_status = 0;
           lists_backedup = true;
-          waypt_backup(&wpt_ct_bak, &wpt_head_bak);
+          waypt_backup(&wpt_head_bak);
           route_backup(&rte_head_bak);
           track_backup(&trk_head_bak);
 
@@ -378,7 +379,8 @@ run(const char* prog_name)
         cet_convert_deinit();
 
         if (lists_backedup) {
-          waypt_restore(wpt_ct_bak, wpt_head_bak);
+          waypt_restore(wpt_head_bak);
+          delete wpt_head_bak;
           route_restore(rte_head_bak);
           delete rte_head_bak;
           track_restore(trk_head_bak);
index 651648204a237dd1af35faa00eb1e9674ec2fad4..b13845120dc80e39a9fbe90067737e3f62c5567d 100644 (file)
 
  */
 
+#include <cmath>                // for fabs
+#include <cstring>              // for memset
+
+#include <QtCore/QDate>         // for QDate
+#include <QtCore/QDateTime>     // for QDateTime
+#include <QtCore/QString>       // for QString
+#include <QtCore/QTime>         // for QTime
+#include <QtCore/Qt>            // for UTC
+#include <QtCore/QtGlobal>      // for foreach
+
 #include "defs.h"
-#include <cctype>
-#include <cmath>
-#include <cstring>
-#include <ctime>
-//#include "session.h"
+#include "gbfile.h"             // for gbfclose, gbfeof, gbfgetint32, gbfputint32, gbfread, gbfwrite, gbfile, gbfopen_le
+#include "session.h"            // for curr_session
+#include "src/core/datetime.h"  // for DateTime
+
 
 #define MYNAME "mapasia"
 
@@ -167,9 +176,7 @@ tr7_check_after_read_wpt_cb(const Waypoint* wpt)
 static void
 tr7_check_after_read_trailer_cb(const route_head* trk)
 {
-  queue* elem, *tmp;
-  QUEUE_FOR_EACH((queue*)&trk->waypoint_list, elem, tmp) {
-    Waypoint* wpt = reinterpret_cast<Waypoint *>(elem);
+  foreach (Waypoint* wpt, trk->waypoint_list) {
     if (speed_tmp == 0) {
       WAYPT_UNSET(wpt, speed);
     }
index 262a2c91ae692dd71ed210ee7bf857e9e80db6a8..bebb844f96a27b688384b7bfaf431784d1474ded 100644 (file)
     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA
  */
 
+#include <cmath>                // for lround
+#include <cstdio>               // for sprintf
+#include <cstdlib>              // for atoi
+#include <cstring>              // for strncpy
+#include <ctime>
+
+#include <QtCore/QCharRef>      // for QCharRef
+#include <QtCore/QString>       // for QString
+#include <QtCore/QTime>         // for QTime
+#include <QtCore/QtGlobal>      // for Q_UNUSED
+
 #include "defs.h"
-#include "magellan.h"
 #include "mapsend.h"
-#include <cmath>
-#include <cstdio>
-#include <cstdlib>
+#include "gbfile.h"             // for gbfputint32, gbfgetint32, gbfgetdbl, gbfputdbl, gbfgetpstr, gbfwrite, gbfputpstr, gbfputc, gbfread, gbfclose, gbfgetc, gbfgetflt, gbfopen, gbfputflt, gbfile, gbfgetuint32, gbfopen_le, gbsize_t
+#include "magellan.h"           // for mag_find_token_from_descr, mag_find_descr_from_token
+#include "src/core/datetime.h"  // for DateTime
+
 
 static gbfile* mapsend_file_in;
 static gbfile* mapsend_file_out;
@@ -395,7 +406,6 @@ static void mapsend_track_hdr(const route_head* trk)
    * tremendously out of whack time/date wise.
    */
   const char* verstring = "30";
-  queue* elem, *tmp;
   mapsend_hdr hdr = {13, {'4','D','5','3','3','3','3','4',' ','M','S'},
     {'3','0'}, ms_type_track, {0, 0, 0}
   };
@@ -428,10 +438,7 @@ static void mapsend_track_hdr(const route_head* trk)
   gbfputpstr(tname, mapsend_file_out);
 
   /* total nodes (waypoints) this track */
-  int i = 0;
-  QUEUE_FOR_EACH(&trk->waypoint_list, elem, tmp) {
-    i++;
-  }
+  int i = trk->waypoint_list.count();
 
   gbfputint32(i, mapsend_file_out);
 
index 17cbcd58f6e9c1181bd715456c8d29f428fbc3d2..090c6edcdb674d248e3f3976b9dcfc542a58014b 100644 (file)
 #include <cstdlib>              // for atoi, rand, srand
 #include <cstring>              // for strcpy, memset, strlen, strcmp
 #include <ctime>                // for time_t
+#include <cstdio>               // for SEEK_CUR
 
 #include <QtCore/QChar>         // for QChar
 #include <QtCore/QFile>         // for QFile
 #include <QtCore/QList>         // for QList
 #include <QtCore/QString>       // for QString, operator==
+#include <QtCore/QtGlobal>      // for foreach
 
 #include "defs.h"
 #include "garmin_tables.h"      // for gt_find_icon_number_from_desc, MAPSOURCE, gt_find_desc_from_icon_number, GARMIN_SERIAL, PCX, garmin_formats_e
 #include "gbfile.h"             // for gbfwrite, gbfread, gbfgetint32, gbfputint32, gbfseek, gbfputc, gbfgetc, gbfputdbl, gbfgetdbl, gbfclose, gbfeof, gbfile, gbftell, gbfgetcstr, gbfputs, gbfopen_le
 #include "jeeps/gpsmath.h"      // for GPS_Math_Deg_To_Semi, GPS_Math_Semi_To_Deg
-#include "queue.h"              // for queue, QUEUE_FOR_EACH
 #include "src/core/datetime.h"  // for DateTime
 
 
@@ -1101,8 +1102,6 @@ mps_routehdr_w(gbfile* mps_file, int mps_ver, const route_head* rte)
   double               maxalt=unknown_alt;
   double               minalt=-unknown_alt;
 
-  queue* elem, *tmp;
-
   prevRouteWpt = nullptr;              /* clear the stateful flag used to know when the start of route wpts happens */
 
   memset(zbuf, 0, sizeof(zbuf));
@@ -1111,9 +1110,9 @@ mps_routehdr_w(gbfile* mps_file, int mps_ver, const route_head* rte)
   unsigned int rte_datapoints = 0;
   int allWptNameLengths = 0;
 
-  if (rte->waypoint_list.next) {               /* this test doesn't do what I want i.e test if this is a valid route - treat as a placeholder for now */
-    QUEUE_FOR_EACH(&rte->waypoint_list, elem, tmp) {
-      Waypoint* testwpt = reinterpret_cast<Waypoint *>(elem);
+  //if (rte->waypoint_list.next) {             /* this test doesn't do what I want i.e test if this is a valid route - treat as a placeholder for now */
+  if (true) {
+    foreach (const Waypoint* testwpt, rte->waypoint_list) {
       if (rte_datapoints == 0) {
         uniqueValue = testwpt->GetCreationTime().toTime_t();
       }
@@ -1420,7 +1419,8 @@ mps_routetrlr_w(gbfile* mps_file, int mps_ver, const route_head* rte)
   (void)mps_ver;
   hdr[0] = 1;
 
-  if (rte->waypoint_list.next) {               /* this test doesn't do what I want i.e test if this is a valid route - treat as a placeholder for now */
+  //if (rte->waypoint_list.next) {             /* this test doesn't do what I want i.e test if this is a valid route - treat as a placeholder for now */
+  if (true) {
     gbfwrite(&value, 4, 1, mps_file);
     gbfwrite(hdr, 1, 1, mps_file);
   }
@@ -1531,16 +1531,14 @@ mps_trackhdr_w(gbfile* mps_file, int mps_ver, const route_head* trk)
   char         hdr[20];
   time_t               uniqueValue = 0;
 
-  queue* elem, *tmp;
-
   (void)mps_ver;
 
   /* total nodes (waypoints) this track */
   unsigned int trk_datapoints = 0;
-  if (trk->waypoint_list.next) {       /* this test doesn't do what I want i.e test if this is a valid track - treat as a placeholder for now */
-    QUEUE_FOR_EACH(&trk->waypoint_list, elem, tmp) {
+  //if (trk->waypoint_list.next) {     /* this test doesn't do what I want i.e test if this is a valid track - treat as a placeholder for now */
+  if (true) {
+    foreach (const Waypoint* testwpt, trk->waypoint_list) {
       if (trk_datapoints == 0) {
-        Waypoint* testwpt = reinterpret_cast<Waypoint *>(elem);
         uniqueValue = testwpt->GetCreationTime().toTime_t();
       }
       trk_datapoints++;
diff --git a/mmo.cc b/mmo.cc
index f211e8cf9bc2b61dff8b5955cb9d48836d198bc1..24cc4367ff327846bd9ca6b4de7c96bf3867129d 100644 (file)
--- a/mmo.cc
+++ b/mmo.cc
 
  */
 
+#include <cctype>                // for isspace
+#include <cerrno>                // for errno
+#include <cstdio>                // for SEEK_CUR, fprintf, size_t, stdout
+#include <cstdlib>               // for abort, strtol
+#include <cstdint>
+#include <cstring>               // for strcmp, strlen, memset, strchr, strncmp
+#include <ctime>
+
+#include <QtCore/QByteArray>     // for QByteArray
+#include <QtCore/QChar>          // for operator==, QChar
+#include <QtCore/QCharRef>       // for QCharRef
+#include <QtCore/QDateTime>      // for QDateTime
+#include <QtCore/QHash>          // for QHash, QHash<>::const_iterator
+#include <QtCore/QLatin1String>  // for QLatin1String
+#include <QtCore/QString>        // for QString, operator==
+#include <QtCore/Qt>             // for CaseInsensitive
+#include <QtCore/QtGlobal>       // for qAsConst, QAddConst<>::Type, foreach, Q_UNUSED
+
 #include "defs.h"
-#include <QtCore/QHash>
-#include <QtCore/QtGlobal>
-#include <cerrno>
-#include <cstdio>
-#include <cstdlib>
+#include "cet.h"                 // for cet_ucs4_to_utf8, cet_utf8_to_ucs4
+#include "gbfile.h"              // for gbfputc, gbfgetuint16, gbfgetc, gbfgetdbl, gbfgetuint32, gbfputflt, gbfputuint32, gbfgetint16, gbfputdbl, gbfputuint16, gbfclose, gbfread, gbfseek, gbfputint16, gbfwrite, gbfcopyfrom, gbfeof, gbfgetflt, gbfgetint32, gbfile, gbfopen, gbfrewind, gbsize_t
+#include "session.h"             // for curr_session, session_t
+#include "src/core/datetime.h"   // for DateTime
+
 
 #define MYNAME "mmo"
 
@@ -1270,7 +1288,6 @@ mmo_write_wpt_cb(const Waypoint* wpt)
 static void
 mmo_write_rte_head_cb(const route_head* rte)
 {
-  queue* elem, *tmp;
   time_t time = 0x7FFFFFFF;
 
   if (rte->rte_waypt_ct <= 0) {
@@ -1279,8 +1296,7 @@ mmo_write_rte_head_cb(const route_head* rte)
 
   mmo_rte = rte;
 
-  QUEUE_FOR_EACH(&rte->waypoint_list, elem, tmp) {
-    Waypoint* wpt = reinterpret_cast<Waypoint*>(elem);
+  foreach (const Waypoint* wpt, rte->waypoint_list) {
     QDateTime t = wpt->GetCreationTime();
     if ((t.isValid()) && (t.toTime_t() < time)) {
       time = t.toTime_t();
@@ -1301,8 +1317,6 @@ mmo_write_rte_head_cb(const route_head* rte)
 static void
 mmo_write_rte_tail_cb(const route_head* rte)
 {
-  queue* elem, *tmp;
-
   if (rte->rte_waypt_ct <= 0) {
     return;
   }
@@ -1323,8 +1337,7 @@ mmo_write_rte_tail_cb(const route_head* rte)
     }
   }
 
-  QUEUE_FOR_EACH(&rte->waypoint_list, elem, tmp) {
-    Waypoint* wpt = reinterpret_cast<Waypoint*>(elem);
+  foreach (const Waypoint* wpt, rte->waypoint_list) {
     int objid = mmo_get_objid(wpt);
     gbfputuint16(objid & 0x7FFF, fout);
   }
index 4645f7ab4225e9e4fb7817de930e4b695a4f2f14..61df8a84476c8dc742fc91cee08b319c334c5fce 100644 (file)
 
  */
 
+#include <cctype>                  // for isspace
+#include <cstdio>                  // for snprintf
+#include <cstdlib>                 // for atoi, atof, qsort, strtol
+#include <cstring>                 // for strcpy, strlen, memset, strncmp, strstr
+#include <ctime>                   // for mktime
+
+#include <QtCore/QString>          // for QString
+#include <QtCore/QtGlobal>         // for foreach
+
 #include "defs.h"
-#include "cet_util.h"
-#include "csv_util.h"
-#include <cctype>
-#include <cstdio>
-#include <cstdlib>
+#include "cet_util.h"              // for cet_convert_init
+#include "csv_util.h"              // for csv_lineparse
+#include "gbfile.h"                // for gbfclose, gbfgetstr, gbfopen, gbfile
+
 
 static gbfile* file_in;
 static char* nseicon = nullptr;
@@ -298,18 +306,11 @@ fix_netstumbler_dupes()
   htable_t* bh = htable;
 
   int i = 0;
-#if NEWQ
   // Why, oh, why is this format running over the entire waypoint list and
   // modifying it?  This seems wrong.
-  extern QList<Waypoint*> waypt_list;
-  foreach(Waypoint* waypointp, waypt_list) {
+  extern WaypointList* global_waypoint_list;
+  foreach(Waypoint* waypointp, *global_waypoint_list) {
     bh->wpt = waypointp;
-#else
-  queue* elem, *tmp;
-  extern queue waypt_head;
-  QUEUE_FOR_EACH(&waypt_head, elem, tmp) {
-    bh->wpt = reinterpret_cast<Waypoint *>(elem);
-#endif
     QString snptr = bh->wpt->shortname;
     QString tmp_sn = snptr.toLower();
     bh->crc = get_crc32(CSTR(tmp_sn), tmp_sn.length());
diff --git a/nmea.cc b/nmea.cc
index 810d9833c81f7b7922c2d899e8bdb5cc6db2f2ce..14d414a8f491a8224d2fde08f0318e58c05acd0b 100644 (file)
--- a/nmea.cc
+++ b/nmea.cc
@@ -26,6 +26,7 @@
 #include <cstdlib>                 // for atoi, atof
 #include <cstring>                 // for strncmp, memset, strlen, strchr, strstr, strrchr
 #include <ctime>                   // for gmtime
+#include <iterator>                // for operator!=, reverse_iterator
 
 #include <QtCore/QByteArray>       // for QByteArray
 #include <QtCore/QChar>            // for QChar, operator==, operator!=
@@ -43,7 +44,6 @@
 #include "gbfile.h"                // for gbfprintf, gbfflush, gbfclose, gbfopen, gbfgetstr, gbfile
 #include "gbser.h"                 // for gbser_set_speed, gbser_flush, gbser_read_line, gbser_deinit, gbser_init, gbser_write
 #include "jeeps/gpsmath.h"         // for GPS_Lookup_Datum_Index, GPS_Math_Known_Datum_To_WGS84_M
-#include "queue.h"                 // for queue, QUEUE_FOR_EACH, QUEUE_LAST
 #include "src/core/datetime.h"     // for DateTime
 #include "src/core/logging.h"      // for Warning
 #include "strptime.h"              // for strptime
@@ -879,7 +879,6 @@ nmea_fix_timestamps(route_head* track)
   }
 
   if (tm.tm_year == 0) {
-    queue* elem, *temp;
     Waypoint* prev = nullptr;
 
     if (optdate == nullptr) {
@@ -890,8 +889,7 @@ nmea_fix_timestamps(route_head* track)
     }
     time_t delta_tm = mkgmtime(&opt_tm);
 
-    QUEUE_FOR_EACH(&track->waypoint_list, elem, temp) {
-      Waypoint* wpt = reinterpret_cast<Waypoint *>(elem);
+    foreach (Waypoint* wpt, track->waypoint_list) {
 
       wpt->creation_time += delta_tm;
       if ((prev != nullptr) && (prev->creation_time > wpt->creation_time)) {
@@ -910,8 +908,8 @@ nmea_fix_timestamps(route_head* track)
 
     /* go backward through the track and complete timestamps */
 
-    for (queue* elem = QUEUE_LAST(&track->waypoint_list); elem != &track->waypoint_list; elem=elem->prev) {
-      Waypoint* wpt = reinterpret_cast<Waypoint *>(elem);
+    for (auto it = track->waypoint_list.crbegin(); it != track->waypoint_list.crend(); ++it) {
+      Waypoint* wpt = *it;
 
       if (wpt->wpt_flags.fmt_use != 0) {
         wpt->wpt_flags.fmt_use = 0; /* reset flag */
index d45779cfd7f2216ca25a0558103236ed3243bc27..58d926faeb260375f1fa788b2b242e55d5962103 100644 (file)
 
  */
 
+#include <QtCore/QString>               // for QString
+#include <QtCore/QStringRef>            // for QStringRef
+#include <QtCore/QXmlStreamAttributes>  // for QXmlStreamAttributes
 
 #include "defs.h"
-#include "xmlgeneric.h"
-#include <QtCore/QXmlStreamAttributes>
+#include "xmlgeneric.h"                 // for cb_cdata, xg_callback, xg_string, cb_start, cb_end, xg_cb_type, xml_deinit, xml_init, xml_read, xg_tag_mapping
+
 
 static int isFirst = 1;
 static route_head* route = nullptr;
@@ -65,8 +68,8 @@ static void
 rd_deinit()
 {
   if (route != nullptr) {
-    Waypoint* head = reinterpret_cast<Waypoint *>QUEUE_FIRST(&route->waypoint_list);
-    Waypoint* tail = reinterpret_cast<Waypoint *>QUEUE_LAST(&route->waypoint_list);
+    Waypoint* head = route->waypoint_list.front();
+    Waypoint* tail = route->waypoint_list.back();
     if (head != nullptr) {
       route->rte_name = head->shortname;
     }
index 75b0e77e19935b82f5c341ff3b188379fdd4a4ab..c9c4ab0e2981ea9631e7dde85a798550fad2898b 100644 (file)
     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA
 
  */
+
+#include <cstdio>           // for sscanf
+#include <cstring>          // for strchr, strlen, strspn
+
+#include <QtCore/QtGlobal>  // for foreach
+
 #include "defs.h"
-#include "filterdefs.h"
+#include "filterdefs.h"     // for global_waypoint_list
 #include "polygon.h"
-#include <cstdio>
+#include "gbfile.h"         // for gbfclose, gbfgetstr, gbfopen, gbfile
+
 
 #if FILTERS_ENABLED
 #define MYNAME "Polygon filter"
@@ -215,8 +222,6 @@ void PolygonFilter::polytest(double lat1, double lon1,
 
 void PolygonFilter::process()
 {
-  queue* elem, * tmp;
-  Waypoint* waypointp;
   extra_data* ed;
   int fileline = 0;
   int first = 1;
@@ -248,12 +253,7 @@ void PolygonFilter::process()
               fileline);
     } else if (lat1 != BADVAL && lon1 != BADVAL &&
                lat2 != BADVAL && lon2 != BADVAL) {
-#if NEWQ
-      foreach (Waypoint* waypointp, waypt_list) {
-#else
-      QUEUE_FOR_EACH(&waypt_head, elem, tmp) {
-        waypointp = reinterpret_cast<Waypoint *>(elem);
-#endif
+      foreach (Waypoint* waypointp, *global_waypoint_list) {
         if (waypointp->extra_data) {
           ed = (extra_data*) waypointp->extra_data;
         } else {
@@ -297,12 +297,7 @@ void PolygonFilter::process()
   }
   gbfclose(file_in);
 
-#if NEWQ
-  foreach (Waypoint* wp, waypt_list) {
-#else
-  QUEUE_FOR_EACH(&waypt_head, elem, tmp) {
-    Waypoint* wp = reinterpret_cast<Waypoint *>(elem);
-#endif
+  foreach (Waypoint* wp, *global_waypoint_list) {
     ed = (extra_data*) wp->extra_data;
     wp->extra_data = nullptr;
     if (ed) {
index 6e6cf4c73f5cb1691c879b1499cacb45037af355..47509de28f2a647488e36457d2596fa02605961b 100644 (file)
 
  */
 
+#include <cmath>            // for fabs
+#include <cstdlib>          // for strtod
+
+#include <QtCore/QtGlobal>  // for foreach
+
 #include "defs.h"
 #include "filterdefs.h"
-#include "grtcirc.h"
+#include "grtcirc.h"        // for RAD, gcdist, radtomiles
 #include "position.h"
-#include <cmath>
-#include <cstdlib>
 
 #if FILTERS_ENABLED
 
@@ -39,22 +42,16 @@ double PositionFilter::gc_distance(double lat1, double lon1, double lat2, double
 }
 
 /* tear through a waypoint queue, processing points by distance */
-void PositionFilter::position_runqueue(queue* q, int nelems, int qtype)
+void PositionFilter::position_runqueue(WaypointList* waypt_list, int nelems, int qtype)
 {
-  queue* elem, * tmp;
   double dist, diff_time;
   int i = 0, anyitem;
 
   Waypoint** comp = (Waypoint**) xcalloc(nelems, sizeof(*comp));
   int* qlist = (int*) xcalloc(nelems, sizeof(*qlist));
 
-#if NEWQ
-  foreach (Waypoint* waypointp, waypt_list) {
+  foreach (Waypoint* waypointp, *waypt_list) {
     comp[i] = waypointp;
-#else
-  QUEUE_FOR_EACH(q, elem, tmp) {
-    comp[i] = reinterpret_cast<Waypoint *>(elem);
-#endif
     qlist[i] = 0;
     i++;
   }
@@ -137,7 +134,7 @@ void PositionFilter::position_process_any_route(const route_head* rh, int type)
 
   if (i) {
     cur_rte = const_cast<route_head*>(rh);
-    position_runqueue(const_cast<queue*>(&rh->waypoint_list), i, type);
+    position_runqueue(&cur_rte->waypoint_list, i, type);
     cur_rte = nullptr;
   }
 
@@ -161,7 +158,7 @@ void PositionFilter::process()
   int i = waypt_count();
 
   if (i) {
-    position_runqueue(&waypt_head, i, wptdata);
+    position_runqueue(global_waypoint_list, i, wptdata);
   }
 
   route_disp_all(position_process_rte_f, nullptr, nullptr);
index e7477aa836ee55a6eec6946a27702f460990d2ba..4c90107f6ca6bed5def828180347d47b1b4df216 100644 (file)
@@ -24,7 +24,6 @@
 
 #include "defs.h"    // for route_head (ptr only), ARG_NOMINMAX, ARGTYPE_FLOAT
 #include "filter.h"  // for Filter
-#include "queue.h"   // for queue
 
 #if FILTERS_ENABLED
 
@@ -70,7 +69,7 @@ private:
   };
 
   double gc_distance(double lat1, double lon1, double lat2, double lon2);
-  void position_runqueue(queue* q, int nelems, int qtype);
+  void position_runqueue(WaypointList* waypt_list, int nelems, int qtype);
   void position_process_any_route(const route_head* rh, int type);
   void position_process_rte(const route_head* rh);
   void position_process_trk(const route_head* rh);
index d8b77d70b4ffae5b8f7dc0b77e8fc1dad35e6ffe..d373bd884d0e1b1e0c1285c4b65f85d94bcea71f 100644 (file)
     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA
  */
 
+#include <cctype>                  // for isspace
+#include <cstdio>                  // for sscanf, EOF, size_t
+#include <cstdlib>                 // for atof, atoi
+#include <cstring>                 // for strcmp, strlen, strcpy
+#include <ctime>                   // for gmtime
+
+#include <QtCore/QChar>            // for QChar
+#include <QtCore/QLatin1String>    // for QLatin1String
+#include <QtCore/QString>          // for QString
+#include <QtCore/QtGlobal>         // for foreach, uint
+
 #include "defs.h"
-#include "garmin_tables.h"
-#include <cctype>
-#include <cstdio>
-#include <cstdlib>
+#include "garmin_tables.h"         // for gt_find_desc_from_icon_number, gt_find_icon_number_from_desc, PCX
+#include "gbfile.h"                // for gbfprintf, gbfeof, gbfile, gbfgetc, gbfclose, gbfgets, gbfopen, gbfputs
+#include "src/core/datetime.h"     // for DateTime
+
 
 #define MYNAME "PSITREX"
 
@@ -451,14 +462,13 @@ psit_routehdr_w(gbfile* psit_file, const route_head* rte)
   QString rname;
 
   /* total nodes (waypoints) this route */
-  if (rte->waypoint_list.next) { 
+  //if (rte->waypoint_list.next) { 
+  if (true) {
     // this test doesn't do what I w ant i.e test if this is a valid 
     // route - treat as a placeholder for now .
     time_t uniqueValue = 0;
     unsigned int rte_datapoints = 0;
-    queue *elem, *tmp;
-    QUEUE_FOR_EACH(&rte->waypoint_list, elem, tmp) {
-      Waypoint* testwpt = reinterpret_cast<Waypoint*>(elem);
+    foreach (const Waypoint* testwpt, rte->waypoint_list) {
       if (rte_datapoints == 0) {
         uniqueValue = testwpt->GetCreationTime().toTime_t();
       }
@@ -591,16 +601,14 @@ psit_trackhdr_w(gbfile* psit_file, const route_head* trk)
   QString tname;
   time_t uniqueValue = 0;
 
-  queue* elem, *tmp;
-
   if (psit_track_state == 2) {
     /* total nodes (waypoints) this track */
-    if (trk->waypoint_list.next) {     /* this test doesn't do what I want i.e test if this is a valid track - treat as a placeholder for now */
+    //if (trk->waypoint_list.next) {   /* this test doesn't do what I want i.e test if this is a valid track - treat as a placeholder for now */
+    if (true) {
 
       unsigned int trk_datapoints = 0;
-      QUEUE_FOR_EACH(&trk->waypoint_list, elem, tmp) {
+      foreach (const Waypoint* testwpt, trk->waypoint_list) {
         if (trk_datapoints == 0) {
-          Waypoint* testwpt = reinterpret_cast<Waypoint*>(elem);
           uniqueValue = testwpt->GetCreationTime().toTime_t();
         }
         trk_datapoints++;
index 0a68b49c5287f839e7ce973656d90ec220695d45..4eb8c8dda85b21a68f7e468d248568f1a65acdda 100644 (file)
--- a/radius.cc
+++ b/radius.cc
     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA
 
  */
+
+#include <cstdlib>          // for atof, atoi, qsort, strtod
+
+#include <QtCore/QString>   // for QString
+#include <QtCore/QtGlobal>  // for foreach
+
 #include "defs.h"
 #include "filterdefs.h"
-#include "grtcirc.h"
 #include "radius.h"
-#include <cstdio>
-#include <cstdlib>
+#include "grtcirc.h"        // for RAD, gcdist, radtomiles
 
 #if FILTERS_ENABLED
 
@@ -56,18 +60,10 @@ int RadiusFilter::dist_comp(const void* a, const void* b)
 
 void RadiusFilter::process()
 {
-#if !NEWQ
-  queue* elem, * tmp;
-#endif
   Waypoint** comp;
   int i, wc;
   route_head* rte_head = nullptr;
-#if NEWQ
-  foreach (Waypoint* waypointp, waypt_list) {
-#else
-  QUEUE_FOR_EACH(&waypt_head, elem, tmp) {
-    Waypoint* waypointp = reinterpret_cast<Waypoint *>(elem);
-#endif
+  foreach (Waypoint* waypointp, *global_waypoint_list) {
     double dist = gc_distance(waypointp->latitude,
                        waypointp->longitude,
                        home_pos->latitude,
@@ -99,12 +95,7 @@ void RadiusFilter::process()
    * for qsort.
    */
 
-#if NEWQ
-  foreach (Waypoint* wp, waypt_list) {
-#else
-  QUEUE_FOR_EACH(&waypt_head, elem, tmp) {
-    Waypoint* wp = reinterpret_cast<Waypoint *>(elem);
-#endif
+  foreach (Waypoint* wp, *global_waypoint_list) {
     comp[i] = wp;
     waypt_del(wp);
     i++;
index 3f85066c2e0c1f8301a437a2eb74f9080344786e..64709a56e5f76a23652c7ee1ed261ae24c687972 100644 (file)
     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA
 
  */
+#include <algorithm>     // for reverse
+
+#include <QtCore/QList>  // for QList<>::iterator
+
 #include "defs.h"
 #include "filterdefs.h"
 #include "reverse_route.h"
@@ -44,10 +48,7 @@ void ReverseRouteFilter::reverse_route_head(const route_head* rte_hd)
 {
   /* Cast away const-ness */
   auto rh = const_cast<route_head*>(rte_hd);
-  queue* elem, *tmp;
-  QUEUE_FOR_EACH(&rh->waypoint_list, elem, tmp) {
-    ENQUEUE_HEAD(&rh->waypoint_list, dequeue(elem));
-  }
+  std::reverse(rh->waypoint_list.begin(), rh->waypoint_list.end());
   prev_new_trkseg = 1;
 }
 
index 81b7ff3989a5b5b88a6f66cedd51c9cda5cc4060..8ef484bb0e9bba4bf437bd1c7bba5167083d5e0d 100644 (file)
--- a/route.cc
+++ b/route.cc
 
  */
 
+#include <cassert>              // for assert
+#include <cstddef>              // for nullptr_t
+#include <algorithm>            // for sort
+#include <iterator>
+
+#include <QtCore/QDateTime>     // for QDateTime
+#include <QtCore/QList>         // for QList<>::iterator
+#include <QtCore/QString>       // for QString
+#include <QtCore/QtGlobal>      // for foreach
+
 #include "defs.h"
 #include "grtcirc.h"            // for RAD, gcdist, heading_true_degrees, radtometers
-#include "queue.h"              // for dequeue, queue, QUEUE_FOR_EACH, QUEUE_EMPTY, ENQUEUE_HEAD, ENQUEUE_TAIL, QUEUE_INIT, QUEUE_LAST, QUEUE_NEXT
 #include "session.h"            // for curr_session, session_t (ptr only)
 #include "src/core/datetime.h"  // for DateTime
 #include "src/core/optional.h"  // for optional, operator>, operator<
-#include <QtCore/QDateTime>     // for QDateTime
-#include <QtCore/QList>         // for QList<>::iterator
-#include <QtCore/QString>       // for QString
-#include <QtCore/QtGlobal>      // for foreach
-#include <algorithm>            // for sort
-#include <cstddef>              // for nullptr_t
+
 
 RouteList* global_route_list;
 RouteList* global_track_list;
@@ -112,7 +116,7 @@ route_add_wpt(route_head* rte, Waypoint* wpt, const QString& namepart, int numbe
   // First point in a route is always a new segment.
   // This improves compatibility when reading from
   // segment-unaware formats.
-  if (QUEUE_EMPTY(&rte->waypoint_list)) {
+  if (rte->waypoint_list.empty()) {
     wpt->wpt_flags.new_trkseg = 1;
   }
 
@@ -125,7 +129,7 @@ track_add_wpt(route_head* rte, Waypoint* wpt, const QString& namepart, int numbe
   // First point in a track is always a new segment.
   // This improves compatibility when reading from
   // segment-unaware formats.
-  if (QUEUE_EMPTY(&rte->waypoint_list)) {
+  if (rte->waypoint_list.empty()) {
     wpt->wpt_flags.new_trkseg = 1;
   }
 
@@ -256,8 +260,7 @@ track_sort(RouteList::Compare cmp)
 computed_trkdata track_recompute(const route_head* trk)
 {
   Waypoint first;
-  Waypoint* prev = &first;
-  queue* elem, *tmp;
+  const Waypoint* prev = &first;
   int tkpt = 0;
   int pts_hrt = 0;
   double tot_hrt = 0.0;
@@ -269,8 +272,7 @@ computed_trkdata track_recompute(const route_head* trk)
 //  first.longitude = 0;
 //  first.creation_time = 0;
 
-  QUEUE_FOR_EACH(&trk->waypoint_list, elem, tmp) {
-    auto thisw = reinterpret_cast<Waypoint*>(elem);
+  foreach (Waypoint* thisw, trk->waypoint_list) {
 
     /*
      * gcdist and heading want radians, not degrees.
@@ -383,12 +385,11 @@ route_head::route_head() :
   line_width(-1),
   session(curr_session())
 {
-  QUEUE_INIT(&waypoint_list);
 };
 
 route_head::~route_head()
 {
-  waypt_flush(&waypoint_list);
+  waypoint_list.flush();
   if (fs) {
     fs_chain_destroy(fs);
   }
@@ -414,6 +415,7 @@ RouteList::del_head(route_head* rte)
 {
   waypt_ct -= rte->rte_waypt_ct;
   const int idx = this->indexOf(rte);
+  assert(idx >= 0);
   removeAt(idx);
   delete rte;
 }
@@ -422,6 +424,7 @@ void
 RouteList::insert_head(route_head* rte, route_head* predecessor)
 {
   const int idx = this->indexOf(predecessor);
+  assert(idx >= 0);
   this->insert(idx + 1, rte);
 }
 
@@ -432,25 +435,18 @@ RouteList::insert_head(route_head* rte, route_head* predecessor)
 void
 RouteList::add_wpt(route_head* rte, Waypoint* wpt, bool synth, const QString& namepart, int number_digits)
 {
-  ENQUEUE_TAIL(&rte->waypoint_list, &wpt->Q);
   rte->rte_waypt_ct++; /* waypoints in this route */
   ++waypt_ct;
-  if (synth && wpt->shortname.isEmpty()) {
-    wpt->shortname = QString("%1%2").arg(namepart).arg(waypt_ct, number_digits, 10, QChar('0'));
-    wpt->wpt_flags.shortname_is_synthetic = 1;
+  rte->waypoint_list.add_rte_waypt(waypt_ct, wpt, synth, namepart, number_digits);
+  if ((this == global_route_list) || (this == global_track_list)) {
+    update_common_traits(wpt);
   }
-  update_common_traits(wpt);
 }
 
 void
 RouteList::del_wpt(route_head* rte, Waypoint* wpt)
 {
-  if (wpt->wpt_flags.new_trkseg && wpt != reinterpret_cast<Waypoint*>QUEUE_LAST(&rte->waypoint_list)) {
-    auto wpt_next = reinterpret_cast<Waypoint*>QUEUE_NEXT(&wpt->Q);
-    wpt_next->wpt_flags.new_trkseg = 1;
-  }
-  wpt->wpt_flags.new_trkseg = 0;
-  dequeue(&wpt->Q);
+  rte->waypoint_list.del_rte_waypt(wpt);
   rte->rte_waypt_ct--;
   --waypt_ct;
 }
@@ -474,18 +470,15 @@ RouteList::common_disp_session(const session_t* se, route_hdr rh, route_trl rt,
 void
 RouteList::flush()
 {
-  foreach (route_head* rte, *this) {
-    delete rte;
+  while (!isEmpty()) {
+    delete takeFirst();
   }
-  clear();
   waypt_ct = 0;
 }
 
 void
 RouteList::copy(RouteList** dst) const
 {
-  queue* elem2, *tmp2;
-
   if (*dst == nullptr) {
     *dst = new RouteList;
   }
@@ -499,8 +492,8 @@ RouteList::copy(RouteList** dst) const
     rte_new->fs = fs_chain_copy(rte_old->fs);
     rte_new->rte_num = rte_old->rte_num;
     (*dst)->add_head(rte_new);
-    QUEUE_FOR_EACH(&rte_old->waypoint_list, elem2, tmp2) {
-      (*dst)->add_wpt(rte_new, new Waypoint(*reinterpret_cast<Waypoint*>(elem2)), false, RPT, 3);
+    foreach (const Waypoint* old_wpt, rte_old->waypoint_list) {
+      (*dst)->add_wpt(rte_new, new Waypoint(*old_wpt), false, RPT, 3);
     }
   }
 }
@@ -529,4 +522,3 @@ void RouteList::sort(Compare cmp)
 {
   std::sort(begin(), end(), cmp);
 }
-
diff --git a/sort.cc b/sort.cc
index 1c636411b3123ad67ae860bb04a9824366732ee6..f8d7b2edf55ffcb7fd730d8e2635880f3f26264b 100644 (file)
--- a/sort.cc
+++ b/sort.cc
     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA
 
  */
+
+#include <QtCore/QDateTime>     // for QDateTime
+#include <QtCore/QString>       // for operator<, QString
+
 #include "defs.h"
+#include "src/core/datetime.h"  // for DateTime
 #include "filterdefs.h"
 #include "sort.h"
-#include <QtCore/QString>    // for QString
-#include <cstdlib>           // for abort
 
 #if FILTERS_ENABLED
 #define MYNAME "sort"
 
-template <class T>
-inline int sgn(T v)
+
+bool SortFilter::sort_comp_wpt_by_description(const Waypoint* a, const Waypoint* b)
 {
-// Returns 1 if v > 0, -1 if v < 0, and 0 if v is zero
-  return (v > T(0)) - (v < T(0));
+  return a->description < b->description;
 }
 
-template <class T>
-inline int cmp(T a, T b)
+bool SortFilter::sort_comp_wpt_by_gcid(const Waypoint* a, const Waypoint* b)
 {
-// Returns 1 if a > b, -1 if a < b, and 0 if a = b
-// note possible overflow in computing sgn(a-b) is avoided.
-  return (a > b) - (a < b);
+  return a->gc_data->id < b->gc_data->id;
 }
 
-int SortFilter::sort_comp_wpt(const queue* a, const queue* b)
+bool SortFilter::sort_comp_wpt_by_shortname(const Waypoint* a, const Waypoint* b)
 {
-  const Waypoint* x1 = reinterpret_cast<const Waypoint*>(a);
-  const Waypoint* x2 = reinterpret_cast<const Waypoint*>(b);
-
-  switch (wpt_sort_mode)  {
-  case SortModeWpt::description:
-    return x1->description.compare(x2->description);
-  case SortModeWpt::gcid:
-    return cmp(x1->gc_data->id, x2->gc_data->id);
-  case SortModeWpt::shortname:
-    return x1->shortname.compare(x2->shortname);
-  case SortModeWpt::time:
-    return sgn(x2->GetCreationTime().msecsTo(x1->GetCreationTime()));
-  default:
-    abort();
-    return 0; /* Internal caller error. */
-  }
+  return a->shortname < b->shortname;
+}
+
+bool SortFilter::sort_comp_wpt_by_time(const Waypoint* a, const Waypoint* b)
+{
+  return a->GetCreationTime() < b->GetCreationTime();
 }
 
 bool SortFilter::sort_comp_rh_by_description(const route_head* a, const route_head* b)
@@ -74,21 +63,30 @@ bool SortFilter::sort_comp_rh_by_name(const route_head* a, const route_head* b)
 
 bool SortFilter::sort_comp_rh_by_number(const route_head* a, const route_head* b)
 {
-  return a->rte_num <  b->rte_num;
-}
-
-int SortFilter::SortCompWptFunctor::operator()(const queue* a, const queue* b)
-{
-  return that->sort_comp_wpt(a, b);
+  return a->rte_num < b->rte_num;
 }
 
 void SortFilter::process()
 {
-  SortCompWptFunctor sort_comp_wpt_f(*this);
-
   if (wpt_sort_mode != SortModeWpt::none) {
-    sortqueue(&waypt_head, sort_comp_wpt_f);
+    switch (wpt_sort_mode) {
+    case SortModeWpt::description:
+      waypt_sort(sort_comp_wpt_by_description);
+      break;
+    case SortModeWpt::gcid:
+      waypt_sort(sort_comp_wpt_by_gcid);
+      break;
+    case SortModeWpt::shortname:
+      waypt_sort(sort_comp_wpt_by_shortname);
+      break;
+    case SortModeWpt::time:
+      waypt_sort(sort_comp_wpt_by_time);
+      break;
+    default:
+      fatal(MYNAME ": unknown waypoint sort mode.");
+    }
   }
+  
   if (rte_sort_mode != SortModeRteHd::none) {
     switch (rte_sort_mode)  {
     case SortModeRteHd::description:
diff --git a/sort.h b/sort.h
index b724ecc32088bc263a691740b6bf6d353cf44367..d6e030b3eb1c4e0212975f6d2a8f01dedbebd101 100644 (file)
--- a/sort.h
+++ b/sort.h
@@ -24,7 +24,6 @@
 
 #include "defs.h"    // for ARGTYPE_BOOL, ARG_NOMINMAX, arglist_t, ARG_TERMI...
 #include "filter.h"  // for Filter
-#include "queue.h"   // for queue
 
 #if FILTERS_ENABLED
 
@@ -107,21 +106,14 @@ private:
     ARG_TERMINATOR
   };
 
-  int sort_comp_wpt(const queue* a, const queue* b);
+  static bool sort_comp_wpt_by_description(const Waypoint* a, const Waypoint* b);
+  static bool sort_comp_wpt_by_gcid(const Waypoint* a, const Waypoint* b);
+  static bool sort_comp_wpt_by_shortname(const Waypoint* a, const Waypoint* b);
+  static bool sort_comp_wpt_by_time(const Waypoint* a, const Waypoint* b);
   static bool sort_comp_rh_by_description(const route_head* a, const route_head* b);
   static bool sort_comp_rh_by_name(const route_head* a, const route_head* b);
   static bool sort_comp_rh_by_number(const route_head* a, const route_head* b);
 
-  class SortCompWptFunctor
-  {
-  public:
-      explicit SortCompWptFunctor(SortFilter& obj) : that(&obj) {}
-    int operator()(const queue* a, const queue* b);
-
-  private:
-    SortFilter* that;
-  };
-
 };
 #endif // FILTERS_ENABLED
 #endif // SORT_H_INCLUDED_
index 3721ab25ae8d9e605f63ca4930b9686415c67c23..d826c5e297dae573591d2a06560a6fc682a07f71 100644 (file)
 
  */
 
+#include <cstdlib>  // for atoi
+
 #include "defs.h"
 #include "filterdefs.h"
 #include "stackfilter.h"
-#include <cstdlib>
 
 #if FILTERS_ENABLED
 
 void StackFilter::process()
 {
   stack_elt* tmp_elt = nullptr;
-  queue* elem = nullptr;
-  queue* tmp = nullptr;
-  queue tmp_queue;
+  WaypointList* waypt_list_ptr;
   RouteList* route_list_ptr;
 
   if (opt_push) {
     tmp_elt = new stack_elt;
-
-    QUEUE_MOVE(&(tmp_elt->waypts), &waypt_head);
-    tmp_elt->waypt_ct = waypt_count();
-    set_waypt_count(0);
     tmp_elt->next = stack;
     stack = tmp_elt;
-    if (opt_copy) {
-      QUEUE_FOR_EACH(&(stack->waypts), elem, tmp) {
-        waypt_add(new Waypoint(*reinterpret_cast<Waypoint *>(elem)));
-      }
+
+    waypt_list_ptr = &(tmp_elt->waypts);
+    waypt_backup(&waypt_list_ptr);
+    if (!opt_copy) {
+      waypt_flush_all();
     }
 
     route_list_ptr = &(tmp_elt->routes);
@@ -68,22 +64,18 @@ void StackFilter::process()
       fatal(MYNAME ": stack empty\n");
     }
     if (opt_append) {
-      QUEUE_FOR_EACH(&(stack->waypts), elem, tmp) {
-        waypt_add(reinterpret_cast<Waypoint *>(elem));
-      }
+      waypt_append(&(stack->waypts));
+      stack->waypts.flush();
       route_append(&(stack->routes));
       stack->routes.flush();
       track_append(&(stack->tracks));
       stack->tracks.flush();
     } else if (opt_discard) {
-      waypt_flush(&(stack->waypts));
+      stack->waypts.flush();
       stack->routes.flush();
       stack->tracks.flush();
     } else {
-      waypt_flush(&waypt_head);
-      QUEUE_MOVE(&(waypt_head), &(stack->waypts));
-      set_waypt_count(stack->waypt_ct);
-
+      waypt_restore(&(stack->waypts));
       route_restore(&(stack->routes));
       track_restore(&(stack->tracks));
     }
@@ -99,12 +91,8 @@ void StackFilter::process()
       tmp_elt = tmp_elt->next;
       swapdepth--;
     }
-    QUEUE_MOVE(&tmp_queue, &(tmp_elt->waypts));
-    QUEUE_MOVE(&(tmp_elt->waypts), &waypt_head);
-    QUEUE_MOVE(&waypt_head, &tmp_queue);
-    unsigned int tmp_count = waypt_count();
-    set_waypt_count(tmp_elt->waypt_ct);
-    tmp_elt->waypt_ct = tmp_count;
+
+    waypt_swap(tmp_elt->waypts);
 
     route_swap(tmp_elt->routes);
 
@@ -165,7 +153,7 @@ void StackFilter::exit()
             "check command line for mistakes\n");
   }
   while (stack) {
-    waypt_flush(&(stack->waypts));
+    stack->waypts.flush();
     stack->routes.flush();
     stack->tracks.flush();
     tmp_elt = stack;
index 2e88cd7859c5df603274b3a43e26860d6972708d..81dc038ec7c65d80ed7888d579197d240a52357f 100644 (file)
@@ -24,7 +24,6 @@
 
 #include "defs.h"    // for ARGTYPE_BOOL, ARG_NOMINMAX, ARGTYPE_BEGIN_EXCL
 #include "filter.h"  // for Filter
-#include "queue.h"   // for queue
 
 #if FILTERS_ENABLED
 
@@ -93,18 +92,11 @@ private:
     ARG_TERMINATOR
   };
 
-  class stack_elt
+  struct stack_elt
   {
-  public:
-    stack_elt()
-    {
-      QUEUE_INIT(&waypts);
-    }
-
-    queue waypts;
+    WaypointList waypts;
     RouteList routes;
     RouteList tracks;
-    unsigned int waypt_ct{0};
     stack_elt* next{nullptr};
   };
   stack_elt* stack = nullptr;
index 70830787fc588932ec5c145ed22b4e884a7b2db5..f175bbcc35badf32497f41e1c253aca10d3d8bff 100644 (file)
--- a/tomtom.cc
+++ b/tomtom.cc
     description string beyond the NUL terminator.  -- Ron Parker, 17 July 2006
 */
 
+#include <cstdio>           // for printf, snprintf, SEEK_CUR, EOF
+#include <cstdlib>          // for qsort
+#include <cstring>          // for strlen
+
+#include <QtCore/QString>   // for QString
+#include <QtCore/QtGlobal>  // for foreach
 
 #include "defs.h"
-#include <QtCore/QTextCodec>
-#include <cstdio> // sprintf
-#include <cstdlib> // qsort
+#include "gbfile.h"         // for gbfgetint32, gbfputint32, gbfclose, gbfgetc, gbfputc, gbfseek, gbfile, gbfeof, gbfread, gbftell, gbfwrite, gbfopen_le
+
 
 #define MYNAME "TomTom"
 
@@ -423,12 +428,7 @@ data_write()
 {
   int ct = waypt_count();
   struct hdr* htable, *bh;
-#if NEWQ
-  extern QList<Waypoint*> waypt_list;
-#else
-  queue* elem, *tmp;
-  extern queue waypt_head;
-#endif
+  extern WaypointList* global_waypoint_list;
   double minlon = 200;
   double maxlon = -200;
   double minlat = 200;
@@ -438,13 +438,8 @@ data_write()
   htable = (struct hdr*) xmalloc(ct * sizeof(*htable));
   bh = htable;
 
-#if NEWQ
   // Iterate with waypt_disp_all?
-  foreach(Waypoint* waypointp, waypt_list) {
-#else
-  QUEUE_FOR_EACH(&waypt_head, elem, tmp) {
-    Waypoint* waypointp = reinterpret_cast<Waypoint *>(elem);
-#endif
+  foreach(Waypoint* waypointp, *global_waypoint_list) {
     bh->wpt = waypointp;
     if (waypointp->longitude > maxlon) {
       maxlon = waypointp->longitude;
diff --git a/tpo.cc b/tpo.cc
index 2cff68ee375ac4a23cc0d86409c4085a8deaa3e2..4db52b0bc57406b3e443d8f55b2d88d071545242 100644 (file)
--- a/tpo.cc
+++ b/tpo.cc
     3.x     "recreation"
 */
 
+#include <cassert>                     // for assert
+#include <cmath>                       // for cos, sqrt
+#include <cstdio>                      // for printf, sprintf, SEEK_CUR, SEEK_SET
+#include <cstdint>
+#include <cstring>                     // for strncmp, strlen, memset
+#include <vector>                      // for vector
+
+#include <QtCore/QByteArray>           // for QByteArray
+#include <QtCore/QChar>                // for operator==, QChar
+#include <QtCore/QCharRef>             // for QCharRef
+#include <QtCore/QScopedArrayPointer>  // for QScopedArrayPointer
+#include <QtCore/QString>              // for QString
+#include <QtCore/QtGlobal>             // for qPrintable, Q_UNUSED
 
 #include "defs.h"
-#include "jeeps/gpsmath.h" /* for datum conversions */
-#include <QtCore/QScopedArrayPointer> // Wish we could use c++11...
-#include <cassert>
-#include <cmath>
-#include <cstdio>
-#include <cstdlib>
-#include <vector>
+#include "gbfile.h"                    // for gbfread, gbfgetc, gbfgetint32, gbfwrite, gbfputint16, gbfseek, gbfgetdbl, gbfgetint16, gbfputdbl, gbfclose, gbfputint32, gbfile, gbfopen_le, gbfgetuint16
+#include "jeeps/gpsmath.h"             // for GPS_Math_WGS84LatLonH_To_XYZ, GPS_Math_WGS84_To_Known_Datum_M, GPS_Math_Deg_To_Rad, GPS_Math_Known_Datum_To_WGS84_M
+
 
 #define MYNAME "TPO"
 
@@ -1614,7 +1623,7 @@ tpo_track_hdr(const route_head* rte)
   unsigned char unknown1[] = { 0xFF, 0x00, 0x00, 0x00 };
   unsigned char bounding_box[8] = { 0x00, 0x80, 0x00, 0x80, 0xFF, 0x7F, 0xFF, 0x7F };
 
-  Waypoint* first_track_waypoint = reinterpret_cast<Waypoint *>QUEUE_FIRST(&rte->waypoint_list);
+  Waypoint* first_track_waypoint = rte->waypoint_list.front();
 
   /* zoom level 1-5 visibility flags */
   gbfwrite(visibility_flags, 1, sizeof(visibility_flags), tpo_file_out);
index 421b079c2a2d006bd5a112c651b9d3cbf5eb1bc1..dc15e6923de8267ac2c3d43ffcd74fdc212f9b22 100644 (file)
 
 #undef TRACKF_DBG
 
-#include "defs.h"
-#include "filterdefs.h"
-#include "queue.h"                         // for queue, QUEUE_FOR_EACH, QUEUE_FIRST, QUEUE_LAST, QUEUE_NEXT
-#include "grtcirc.h"                       // for RAD, gcdist, heading_true_degrees, radtometers, radtomiles
-#include "strptime.h"
-#include "trackfilter.h"
-#include "src/core/datetime.h"             // for DateTime
+#include <cassert>                         // for assert
+#include <cmath>                           // for nan
+#include <cstdio>                          // for printf
+#include <cstdlib>                         // for abs
+#include <cstring>                         // for strlen, strchr, strcmp
+#include <ctime>                           // for gmtime, strftime
+#include <iterator>                        // for next
+
+#include <algorithm>                       // for sort, stable_sort
+
 #include <QtCore/QByteArray>               // for QByteArray
 #include <QtCore/QChar>                    // for QChar
 #include <QtCore/QDate>                    // for QDate
 #ifdef TRACKF_DBG
 #include <QtCore/QDebug>
 #endif
-#include <QtCore/QList>                    // for QList<>::iterator, QList
-#include <QtCore/QtGlobal>                 // for qint64, qPrintable
+#include <QtCore/QList>                    // for QList<>::iterator, QList, QList<>::const_iterator
 #include <QtCore/QRegExp>                  // for QRegExp, QRegExp::WildcardUnix
 #include <QtCore/QRegularExpression>       // for QRegularExpression, QRegularExpression::CaseInsensitiveOption, QRegularExpression::PatternOptions
 #include <QtCore/QRegularExpressionMatch>  // for QRegularExpressionMatch
 #include <QtCore/QString>                  // for QString
 #include <QtCore/Qt>                       // for UTC, CaseInsensitive
-#include <algorithm>                       // for sort, stable_sort
-#include <cassert>                         // for assert
-#include <cmath>                           // for nan
-#include <cstdio>                          // for printf
-#include <cstdlib>                         // for abs
-#include <cstring>                         // for strlen, strchr, strcmp
-#include <ctime>                           // for gmtime, strftime
+#include <QtCore/QtGlobal>                 // for qAsConst, foreach, qPrintable, QAddConst<>::Type, qint64
+
+#include "defs.h"
+#include "filterdefs.h"
+#include "trackfilter.h"
+
+#include "grtcirc.h"                       // for RAD, gcdist, radtometers, heading_true_degrees
+#include "src/core/datetime.h"             // for DateTime
+
 
 #if FILTERS_ENABLED || MINIMAL_FILTERS
 #define MYNAME "trackfilter"
@@ -153,27 +157,25 @@ fix_type TrackFilter::trackfilter_parse_fix(int* nsats)
 
 QDateTime TrackFilter::trackfilter_get_first_time(const route_head* track)
 {
-  if (QUEUE_EMPTY(&track->waypoint_list)) {
+  if (track->waypoint_list.empty()) {
     return QDateTime();
   } else {
-    return reinterpret_cast<Waypoint*>(QUEUE_FIRST(&track->waypoint_list))->GetCreationTime();
+    return track->waypoint_list.front()->GetCreationTime();
   }
 }
 
 QDateTime TrackFilter::trackfilter_get_last_time(const route_head* track)
 {
-  if (QUEUE_EMPTY(&track->waypoint_list)) {
+  if (track->waypoint_list.empty()) {
     return QDateTime();
   } else {
-    return reinterpret_cast<Waypoint*>(QUEUE_LAST(&track->waypoint_list))->GetCreationTime();
+    return track->waypoint_list.back()->GetCreationTime();
   }
 }
 
 
 void TrackFilter::trackfilter_fill_track_list_cb(const route_head* track)      /* callback for track_disp_all */
 {
-  queue* elem, *tmp;
-
   if (track->rte_waypt_ct == 0) {
     track_del_head(const_cast<route_head*>(track));
     return;
@@ -181,8 +183,7 @@ void TrackFilter::trackfilter_fill_track_list_cb(const route_head* track)   /* ca
 
   if (opt_name != nullptr) {
     if (!QRegExp(opt_name, Qt::CaseInsensitive, QRegExp::WildcardUnix).exactMatch(track->rte_name)) {
-      QUEUE_FOR_EACH(&track->waypoint_list, elem, tmp) {
-        auto wpt = reinterpret_cast<Waypoint*>(elem);
+      foreach (Waypoint* wpt, track->waypoint_list) {
         track_del_wpt(const_cast<route_head*>(track), wpt);
         delete wpt;
       }
@@ -191,10 +192,9 @@ void TrackFilter::trackfilter_fill_track_list_cb(const route_head* track)  /* ca
     }
   }
 
-  Waypoint* prev = nullptr;
+  const Waypoint* prev = nullptr;
 
-  QUEUE_FOR_EACH(&track->waypoint_list, elem, tmp) {
-    auto wpt = reinterpret_cast<Waypoint*>(elem);
+  foreach (const Waypoint* wpt, track->waypoint_list) {
     if (!(opt_merge && opt_discard) && need_time && (!wpt->creation_time.isValid())) {
       fatal(MYNAME "-init: Found track point at %f,%f without time!\n",
             wpt->latitude, wpt->longitude);
@@ -263,7 +263,7 @@ void TrackFilter::trackfilter_pack_init_rte_name(route_head* track, const QDateT
     if (track->rte_waypt_ct == 0) {
       dt = default_time;
     } else {
-      auto wpt = reinterpret_cast<Waypoint*>QUEUE_FIRST(&track->waypoint_list);
+      auto wpt = track->waypoint_list.front();
       dt = wpt->GetCreationTime();
     }
     time_t t = dt.toTime_t();
@@ -320,9 +320,7 @@ void TrackFilter::trackfilter_pack()
     while (track_list.size() > 1) {
       route_head* curr = track_list.takeAt(1);
 
-      queue* elem, *tmp;
-      QUEUE_FOR_EACH(&curr->waypoint_list, elem, tmp) {
-        auto wpt = reinterpret_cast<Waypoint*>(elem);
+      foreach (Waypoint* wpt, curr->waypoint_list) {
         track_del_wpt(curr, wpt);
         track_add_wpt(master, wpt);
       }
@@ -347,9 +345,7 @@ void TrackFilter::trackfilter_merge()
     auto it = track_list.begin();
     while (it != track_list.end()) { /* put all points into temp buffer */
       route_head* track = *it;
-      queue* elem, *tmp;
-      QUEUE_FOR_EACH(&track->waypoint_list, elem, tmp) {
-        auto wpt = reinterpret_cast<Waypoint*>(elem);
+      foreach (Waypoint* wpt, track->waypoint_list) {
         track_del_wpt(track, wpt); /* copies any new_trkseg flag forward, and clears new_trkseg flag. */
         if (wpt->creation_time.isValid()) {
           // we will put the merged points in one track segment,
@@ -410,7 +406,6 @@ void TrackFilter::trackfilter_split()
     route_head* master = track_list.first();
     int count = master->rte_waypt_ct;
 
-    queue* elem, *tmp;
     int i, j;
     double interval = -1; /* seconds */
     double distance = -1; /* meters */
@@ -490,8 +485,8 @@ void TrackFilter::trackfilter_split()
 
     QList<Waypoint*> buff;
 
-    QUEUE_FOR_EACH(&master->waypoint_list, elem, tmp) {
-      buff.append(reinterpret_cast<Waypoint*>(elem));
+    foreach (Waypoint* wpt, master->waypoint_list) {
+      buff.append(wpt);
     }
 
     trackfilter_split_init_rte_name(master, buff.at(0)->GetCreationTime());
@@ -566,16 +561,13 @@ void TrackFilter::trackfilter_split()
 
 void TrackFilter::trackfilter_move()
 {
-  queue* elem, *tmp;
-
   qint64 delta = trackfilter_parse_time_opt(opt_move);
   if (delta == 0) {
     return;
   }
 
   for (auto track : qAsConst(track_list)) {
-    QUEUE_FOR_EACH(&track->waypoint_list, elem, tmp) {
-      auto wpt = reinterpret_cast<Waypoint*>(elem);
+    foreach (Waypoint* wpt, track->waypoint_list) {
       wpt->creation_time = wpt->creation_time.addSecs(delta);
     }
   }
@@ -587,8 +579,6 @@ void TrackFilter::trackfilter_move()
 
 void TrackFilter::trackfilter_synth()
 {
-  queue* elem, *tmp;
-
   double last_course_lat;
   double last_course_lon;
   double last_speed_lat = std::nan(""); /* Quiet gcc 7.3.0 -Wmaybe-uninitialized */
@@ -600,8 +590,7 @@ void TrackFilter::trackfilter_synth()
 
   for (auto track : qAsConst(track_list)) {
     bool first = true;
-    QUEUE_FOR_EACH(&track->waypoint_list, elem, tmp) {
-      auto wpt = reinterpret_cast<Waypoint*>(elem);
+    foreach (Waypoint* wpt, track->waypoint_list) {
       if (opt_fix) {
         wpt->fix = fix;
         if (wpt->sat == 0) {
@@ -694,7 +683,6 @@ QDateTime TrackFilter::trackfilter_range_check(const char* timestr)
 void TrackFilter::trackfilter_range()
 {
   QDateTime start, stop; // constructed such that isValid() is false, unlike gpsbabel::DateTime!
-  queue* elem, *tmp;
 
   if (opt_start != nullptr) {
     start = trackfilter_range_check(opt_start);
@@ -710,8 +698,7 @@ void TrackFilter::trackfilter_range()
   while (it != track_list.end()) {
     route_head* track = *it;
 
-    QUEUE_FOR_EACH(&track->waypoint_list, elem, tmp) {
-      auto wpt = reinterpret_cast<Waypoint*>(elem);
+    foreach (Waypoint* wpt, track->waypoint_list) {
       bool inside;
       if (wpt->creation_time.isValid()) {
         bool after_start = !start.isValid() || (wpt->GetCreationTime() >= start);
@@ -751,15 +738,13 @@ void TrackFilter::trackfilter_seg2trk()
   if (!track_list.isEmpty()) {
     QList<route_head*> new_track_list;
     for (auto src : qAsConst(track_list)) {
-      queue* elem, *tmp;
       new_track_list.append(src);
       route_head* dest = nullptr;
       route_head* insert_point = src;
       int trk_seg_num = 1;
       bool first = true;
 
-      QUEUE_FOR_EACH(&src->waypoint_list, elem, tmp) {
-        auto wpt = reinterpret_cast<Waypoint*>(elem);
+      foreach (Waypoint* wpt, src->waypoint_list) {
         if (wpt->wpt_flags.new_trkseg && !first) {
 
           dest = route_head_alloc();
@@ -807,10 +792,8 @@ void TrackFilter::trackfilter_trk2seg()
     while (track_list.size() > 1) {
       route_head* curr = track_list.takeAt(1);
 
-      queue* elem, *tmp;
       bool first = true;
-      QUEUE_FOR_EACH(&curr->waypoint_list, elem, tmp) {
-        auto wpt = reinterpret_cast<Waypoint*>(elem);
+      foreach (Waypoint* wpt, curr->waypoint_list) {
 
         unsigned orig_new_trkseg = wpt->wpt_flags.new_trkseg;
         wpt->wpt_flags.new_trkseg = 0;
@@ -872,14 +855,11 @@ TrackFilter::faketime_t TrackFilter::trackfilter_faketime_check(const char* time
 
 void TrackFilter::trackfilter_faketime()
 {
-  queue* elem, *tmp;
-
   assert(opt_faketime != nullptr);
   faketime_t faketime = trackfilter_faketime_check(opt_faketime);
 
   for (auto track : qAsConst(track_list)) {
-    QUEUE_FOR_EACH(&track->waypoint_list, elem, tmp) {
-      auto wpt = reinterpret_cast<Waypoint*>(elem);
+    foreach (Waypoint* wpt, track->waypoint_list) {
 
       if (!wpt->creation_time.isValid() || faketime.force) {
         wpt->creation_time = faketime.start;
@@ -914,7 +894,6 @@ bool TrackFilter::trackfilter_points_are_same(const Waypoint* wpta, const Waypoi
 
 void TrackFilter::trackfilter_segment_head(const route_head* rte)
 {
-  queue* elem, *tmp;
   double avg_dist = 0;
   int index = 0;
   Waypoint* prev_wpt = nullptr;
@@ -922,8 +901,8 @@ void TrackFilter::trackfilter_segment_head(const route_head* rte)
   // (Empirically determined; It's a few dozen feet.)
   const double ktoo_close = 0.000005;
 
-  QUEUE_FOR_EACH(&rte->waypoint_list, elem, tmp) {
-    auto wpt = reinterpret_cast<Waypoint*>(elem);
+  for (auto it = rte->waypoint_list.cbegin(); it != rte->waypoint_list.cend(); ++it) {
+    auto wpt = *it;
     if (index > 0) {
       double cur_dist = gcdist(RAD(prev_wpt->latitude),
                                RAD(prev_wpt->longitude),
@@ -935,8 +914,8 @@ void TrackFilter::trackfilter_segment_head(const route_head* rte)
       }
 
       if (cur_dist < ktoo_close) {
-        if (wpt != reinterpret_cast<Waypoint*>QUEUE_LAST(&rte->waypoint_list)) {
-          auto next_wpt = reinterpret_cast<Waypoint*>QUEUE_NEXT(&wpt->Q);
+        if (wpt != rte->waypoint_list.back()) {
+          auto next_wpt = *std::next(it);
           if (trackfilter_points_are_same(prev_wpt, wpt) &&
               trackfilter_points_are_same(wpt, next_wpt)) {
             track_del_wpt(const_cast<route_head*>(rte), wpt);
index 96dd8cecc6e49d5b8674891bcaedd7e15b9802c3..7845ed0869e4d5ac8e814fd5a1fafb84f7efb122 100644 (file)
@@ -23,7 +23,9 @@
 #define TRACKFILTER_H_INCLUDED_
 
 #include <QtCore/QDateTime>  // for QDateTime
+#include <QtCore/QList>      // for QList
 #include <QtCore/QtGlobal>   // for qint64
+
 #include "defs.h"            // for ARG_NOMINMAX, route_head (ptr only), ARG...
 #include "filter.h"          // for Filter
 
index 6cadb9358053edc2996c3ca72a7e08790f40bfe7..ccb10dfeb1115f530137f4cb2ccce14423694e15 100644 (file)
 
  */
 
+#include <cctype>           // for toupper
+#include <cstdlib>          // for atoi
+
+#include <QtCore/QtGlobal>  // for foreach
+
 #include "defs.h"
 #include "filterdefs.h"
 #include "transform.h"
-#include <cstdlib>
+
 
 #if FILTERS_ENABLED
 
@@ -42,13 +47,7 @@ void TransformFilter::transform_waypoints()
     track_add_head(rte);
     break;
   }
-#if NEWQ
-  foreach (Waypoint* wpt, waypt_list) {
-#else
-  queue* elem, *tmp;
-  QUEUE_FOR_EACH(&waypt_head, elem, tmp) {
-    Waypoint* wpt = reinterpret_cast<Waypoint *>(elem);
-#endif
+  foreach (Waypoint* wpt, *global_waypoint_list) {
 
     wpt = new Waypoint(*wpt);
     switch (current_target) {
index 6a705c05cd4e0cb51060440d0b1c2759d9d5930a..d65ea7af1b08cf2eced3f8f1262e60b59bf0eec7 100644 (file)
--- a/waypt.cc
+++ b/waypt.cc
 
  */
 
+#include <cassert>              // for assert
 #include <cmath>                // for fabs
 #include <cstdio>               // for printf, fflush, fprintf, stdout
 #include <ctime>                // for time_t
+#include <algorithm>            // for stable_sort
 
 #include <QtCore/QByteArray>    // for QByteArray
+#include <QtCore/QChar>         // for QChar
 #include <QtCore/QDateTime>     // for QDateTime
-#include <QtCore/QDebug>
 #include <QtCore/QList>         // for QList
 #include <QtCore/QString>       // for QString, operator==
 #include <QtCore/QTime>         // for QTime
 #include "defs.h"
 #include "garmin_fs.h"          // for garmin_ilink_t, garmin_fs_s, GMSD_FIND, garmin_fs_p
 #include "grtcirc.h"            // for RAD, gcdist, heading_true_degrees, radtometers
-#include "queue.h"              // for queue, QUEUE_INIT, dequeue, QUEUE_FOR_EACH, QUEUE_MOVE, ENQUEUE_TAIL
 #include "session.h"            // for curr_session, session_t
 #include "src/core/datetime.h"  // for DateTime
 #include "src/core/logging.h"   // for Warning, Fatal
 
-#if NEWQ
-QList<Waypoint*> waypt_list;
-queue waypt_head; // This is here solely to freak out the formats that are
-// looking into what should be a private members.
-#else
-queue waypt_head;
-#endif
+WaypointList* global_waypoint_list;
 
-static unsigned int waypt_ct;
 static short_handle mkshort_handle;
 geocache_data Waypoint::empty_gc_data;
 static global_trait traits;
@@ -61,11 +55,7 @@ void
 waypt_init()
 {
   mkshort_handle = mkshort_new_handle();
-#if NEWQ
-  waypt_list.clear();
-#else
-  QUEUE_INIT(&waypt_head);
-#endif
+  global_waypoint_list = new WaypointList;
 }
 
 void update_common_traits(const Waypoint* wpt)
@@ -87,97 +77,22 @@ void update_common_traits(const Waypoint* wpt)
 void
 waypt_add(Waypoint* wpt)
 {
-  double lat_orig = wpt->latitude;
-  double lon_orig = wpt->longitude;
-#if NEWQ
-  waypt_list.append(wpt);
-#else
-  ENQUEUE_TAIL(&waypt_head, &wpt->Q);
-  waypt_ct++;
-#endif
-
-
-  if (wpt->latitude < -90) {
-    wpt->latitude += 180;
-  } else if (wpt->latitude > +90) {
-    wpt->latitude -= 180;
-  }
-  if (wpt->longitude < -180) {
-    wpt->longitude += 360;
-  } else if (wpt->longitude > +180) {
-    wpt->longitude -= 360;
-  }
-
-  if ((wpt->latitude < -90) || (wpt->latitude > 90.0))
-    Fatal() << wpt->session->name
-            << "Invalid latitude" << lat_orig << "in waypoint"
-            << wpt->shortname;
-  if ((wpt->longitude < -180) || (wpt->longitude > 180.0))
-    Fatal() << "Invalid longitude" << lon_orig << "in waypoint"
-            << wpt->shortname;
-
-  /*
-   * Some input may not have one or more of these types so we
-   * try to be sure that we have these fields even if just by
-   * copying them from elsewhere.
-   */
-
-  // Note tests for isNull here as some formats intentionally set "".
-  // This is kind of goofy, but it emulates the C string implementation.
-  if (wpt->shortname.isNull()) {
-    if (!wpt->description.isNull()) {
-      wpt->shortname = wpt->description;
-    } else if (!wpt->notes.isNull()) {
-      wpt->shortname = wpt->notes;
-    } else {
-      QString n;
-      n.sprintf("%03d", waypt_count());
-      wpt->shortname = QString("WPT%1").arg(n);
-    }
-  }
-
-  if (wpt->description.isEmpty()) {
-    if (!wpt->notes.isNull()) {
-      wpt->description = wpt->notes;
-    } else {
-      if (!wpt->shortname.isNull()) {
-        wpt->description = wpt->shortname;
-      }
-    }
-  }
-
-  update_common_traits(wpt);
-
+  global_waypoint_list->waypt_add(wpt);
 }
 
 void
 waypt_del(Waypoint* wpt)
 {
-  // the wpt must be on waypt_list, and is assumed unique.
-#if NEWQ
-  waypt_list.removeOne(wpt);
-#else
-  dequeue(&wpt->Q);
-  waypt_ct--;
-#endif
+  global_waypoint_list->waypt_del(wpt);
 }
 
 unsigned int
 waypt_count()
 {
-#if NEWQ
-  return waypt_list.size();
-#else
-  return waypt_ct;
-#endif
-}
-
-void
-set_waypt_count(unsigned int nc)
-{
-  waypt_ct = nc;
+  return global_waypoint_list->count();
 }
 
+// TODO: should this, and mkshort_handle, be part of main, which is the only user?
 void
 waypt_disp(const Waypoint* wpt)
 {
@@ -263,128 +178,52 @@ waypt_add_to_bounds(bounds* bounds, const Waypoint* waypointp)
 void
 waypt_compute_bounds(bounds* bounds)
 {
-  waypt_init_bounds(bounds);
-#if NEWQ
-  foreach (Waypoint* waypointp, waypt_list) {
-#else
-  queue* elem, *tmp;
-  QUEUE_FOR_EACH(&waypt_head, elem, tmp) {
-    Waypoint* waypointp = reinterpret_cast<Waypoint*>(elem);
-#endif
-    waypt_add_to_bounds(bounds, waypointp);
-  }
+  global_waypoint_list->waypt_compute_bounds(bounds);
 }
 
 Waypoint*
 find_waypt_by_name(const QString& name)
 {
-#if NEWQ
-  foreach (Waypoint* waypointp, waypt_list) {
-#else
-  queue* elem, *tmp;
-
-  QUEUE_FOR_EACH(&waypt_head, elem, tmp) {
-    Waypoint* waypointp = reinterpret_cast<Waypoint*>(elem);
-#endif
-    if (waypointp->shortname == name) {
-      return waypointp;
-    }
-  }
-
-  return nullptr;
+  return global_waypoint_list->find_waypt_by_name(name);
 }
 
-#if NEWQ
 void
-waypt_flush(queue* head)
+waypt_flush_all()
 {
-// TODO: This is incorrect when head != &waypt_head
-// We need to pass in a QList<Waypoint*> instead of a queue* that we ignore!
-  if (head != &waypt_head) {
-    if (global_opts.debug_level >= 1) {
-      warning("NEWQ version of waypt_flush is unimplemented for this list.\n");
-    }
-  } else {
-    while (!waypt_list.isEmpty()) {
-      delete waypt_list.takeFirst();
-    }
+  if (mkshort_handle) {
+    mkshort_del_handle(&mkshort_handle);
   }
+  global_waypoint_list->flush();
 }
-#else
+
 void
-waypt_flush(queue* head)
+waypt_append(WaypointList* src)
 {
-  queue* elem, *tmp;
-
-  QUEUE_FOR_EACH(head, elem, tmp) {
-    Waypoint* q = reinterpret_cast<Waypoint*>(dequeue(elem));
-    delete q;
-    if (head == &waypt_head) {
-      waypt_ct--;
-    }
-  }
+  src->copy(&global_waypoint_list);
 }
-#endif
 
 void
-waypt_flush_all()
+waypt_backup(WaypointList** head_bak)
 {
-  if (mkshort_handle) {
-    mkshort_del_handle(&mkshort_handle);
-  }
-#if NEWQ
-  // TODO: eventually we shoud pass the list instead of the queue.
-  waypt_flush(&waypt_head);
-#else
-  waypt_flush(&waypt_head);
-#endif
+  global_waypoint_list->copy(head_bak);
 }
 
 void
-waypt_backup(signed int* count, queue** head_bak)
+waypt_restore(WaypointList* head_bak)
 {
-  queue* elem, *tmp;
-  Waypoint* wpt;
-  int no = 0;
-
-  queue* qbackup = (queue*) xcalloc(1, sizeof(*qbackup));
-  QUEUE_INIT(qbackup);
-#if NEWQ
-// Why does this code exist?
-//abort();
-#else
-  QUEUE_MOVE(qbackup, &waypt_head);
-  QUEUE_INIT(&waypt_head);
-#endif
-
-  waypt_ct = 0;
-
-  QUEUE_FOR_EACH(qbackup, elem, tmp) {
-    wpt = reinterpret_cast<Waypoint*>(elem);
-    waypt_add(new Waypoint(*wpt));
-    no++;
-  }
-
-  *head_bak = qbackup;
-  *count = no;
+  global_waypoint_list->restore(head_bak);
 }
 
 void
-waypt_restore(signed int count, queue* head_bak)
+waypt_swap(WaypointList& other)
 {
-  if (head_bak == nullptr) {
-    return;
-  }
+  global_waypoint_list->swap(other);
+}
 
-#if NEWQ
-//abort();
-#else
-  waypt_flush(&waypt_head);
-  QUEUE_INIT(&waypt_head);
-  QUEUE_MOVE(&waypt_head, head_bak);
-#endif
-  waypt_ct = count;
-  xfree(head_bak);
+void
+waypt_sort(WaypointList::Compare cmp)
+{
+  global_waypoint_list->sort(cmp);
 }
 
 void
@@ -568,7 +407,6 @@ waypt_course(const Waypoint* A, const Waypoint* B)
 }
 
 Waypoint::Waypoint() :
-  // Q(),
   latitude(0),  // These should probably use some invalid data, but
   longitude(0), // it looks like we have code that relies on them being zero.
   altitude(unknown_alt),
@@ -593,7 +431,6 @@ Waypoint::Waypoint() :
   session(curr_session()),
   extra_data(nullptr)
 {
-  QUEUE_INIT(&Q);
 }
 
 Waypoint::~Waypoint()
@@ -605,7 +442,6 @@ Waypoint::~Waypoint()
 }
 
 Waypoint::Waypoint(const Waypoint& other) :
-  // Q(other.Q),
   latitude(other.latitude),
   longitude(other.longitude),
   altitude(other.altitude),
@@ -642,12 +478,6 @@ Waypoint::Waypoint(const Waypoint& other) :
     gc_data = new geocache_data(*other.gc_data);
   }
 
-  /*
-   * It's important that this duplicated waypoint not appear
-   * on the master Q.
-   */
-  QUEUE_INIT(&Q);
-
   // deep copy fs chain data.
   fs = fs_chain_copy(other.fs);
 
@@ -666,7 +496,6 @@ Waypoint& Waypoint::operator=(const Waypoint& rhs)
     fs_chain_destroy(fs);
 
     // allocate and copy
-    // Q(rhs.Q),
     latitude = rhs.latitude;
     longitude = rhs.longitude;
     altitude = rhs.altitude;
@@ -702,12 +531,6 @@ Waypoint& Waypoint::operator=(const Waypoint& rhs)
       gc_data = new geocache_data(*rhs.gc_data);
     }
 
-    /*
-     * It's important that this duplicated waypoint not appear
-     * on the master Q.
-     */
-    QUEUE_INIT(&Q);
-
     // deep copy fs chain data.
     fs = fs_chain_copy(rhs.fs);
 
@@ -750,7 +573,6 @@ Waypoint::CreationTimeXML() const
   }
 
   QDateTime dt = GetCreationTime().toUTC();
-// qDebug() << dt.toString("dd.MM.yyyy hh:mm:ss.zzz")  << " CML " << microseconds;
 
   const char* format = "yyyy-MM-ddTHH:mm:ssZ";
   if (dt.time().msec()) {
@@ -799,3 +621,167 @@ Waypoint::EmptyGCData() const
 {
   return (gc_data == &Waypoint::empty_gc_data);
 }
+
+void
+WaypointList::waypt_add(Waypoint* wpt)
+{
+  double lat_orig = wpt->latitude;
+  double lon_orig = wpt->longitude;
+  append(wpt);
+
+  if (wpt->latitude < -90) {
+    wpt->latitude += 180;
+  } else if (wpt->latitude > +90) {
+    wpt->latitude -= 180;
+  }
+  if (wpt->longitude < -180) {
+    wpt->longitude += 360;
+  } else if (wpt->longitude > +180) {
+    wpt->longitude -= 360;
+  }
+
+  if ((wpt->latitude < -90) || (wpt->latitude > 90.0))
+    Fatal() << wpt->session->name
+            << "Invalid latitude" << lat_orig << "in waypoint"
+            << wpt->shortname;
+  if ((wpt->longitude < -180) || (wpt->longitude > 180.0))
+    Fatal() << "Invalid longitude" << lon_orig << "in waypoint"
+            << wpt->shortname;
+
+  /*
+   * Some input may not have one or more of these types so we
+   * try to be sure that we have these fields even if just by
+   * copying them from elsewhere.
+   */
+
+  // Note tests for isNull here as some formats intentionally set "".
+  // This is kind of goofy, but it emulates the C string implementation.
+  if (wpt->shortname.isNull()) {
+    if (!wpt->description.isNull()) {
+      wpt->shortname = wpt->description;
+    } else if (!wpt->notes.isNull()) {
+      wpt->shortname = wpt->notes;
+    } else {
+      QString n;
+      n.sprintf("%03d", waypt_count());
+      wpt->shortname = QString("WPT%1").arg(n);
+    }
+  }
+
+  if (wpt->description.isEmpty()) {
+    if (!wpt->notes.isNull()) {
+      wpt->description = wpt->notes;
+    } else {
+      if (!wpt->shortname.isNull()) {
+        wpt->description = wpt->shortname;
+      }
+    }
+  }
+
+  if (this == global_waypoint_list) {
+    update_common_traits(wpt);
+  }
+
+}
+
+void
+WaypointList::add_rte_waypt(int waypt_ct, Waypoint* wpt, bool synth, const QString& namepart, int number_digits)
+{
+  append(wpt);
+
+   if (synth && wpt->shortname.isEmpty()) {
+     wpt->shortname = QString("%1%2").arg(namepart).arg(waypt_ct, number_digits, 10, QChar('0'));
+     wpt->wpt_flags.shortname_is_synthetic = 1;
+   }
+}
+
+void
+WaypointList::waypt_del(Waypoint* wpt)
+{
+  const int idx = this->indexOf(wpt);
+  assert(idx >= 0);
+  removeAt(idx);
+}
+
+void
+WaypointList::del_rte_waypt(Waypoint* wpt)
+{
+  const int idx = indexOf(wpt);
+  assert(idx >= 0);
+  if (wpt->wpt_flags.new_trkseg && ((idx+1) < size())) {
+    auto wpt_next = at(idx+1);
+    wpt_next->wpt_flags.new_trkseg = 1;
+  }
+  wpt->wpt_flags.new_trkseg = 0;
+  removeAt(idx);
+}
+
+/*
+ *  Makes another pass over the data to compute bounding
+ *  box data and populates bounding box information.
+ */
+
+void
+WaypointList::waypt_compute_bounds(bounds* bounds) const
+{
+  waypt_init_bounds(bounds);
+  foreach (const Waypoint* waypointp, *this) {
+    waypt_add_to_bounds(bounds, waypointp);
+  }
+}
+
+Waypoint*
+WaypointList::find_waypt_by_name(const QString& name) const
+{
+  foreach (Waypoint* waypointp, *this) {
+    if (waypointp->shortname == name) {
+      return waypointp;
+    }
+  }
+
+  return nullptr;
+}
+
+void
+WaypointList::flush()
+{
+  while (!isEmpty()) {
+    delete takeFirst();
+  }
+}
+
+void
+WaypointList::copy(WaypointList** dst) const
+{
+  if (*dst == nullptr) {
+    *dst = new WaypointList;
+  }
+    
+  foreach (const Waypoint* wpt_old, *this) {
+    (*dst)->waypt_add(new Waypoint(*wpt_old));
+  }
+}
+
+void
+WaypointList::restore(WaypointList* src)
+{
+  if (src == nullptr) {
+    return;
+  }
+  flush();
+
+  *this = *src;
+  src->clear();
+}
+
+void WaypointList::swap(WaypointList& other)
+{
+  const WaypointList tmp_list = *this;
+  *this = other;
+  other = tmp_list;
+}
+
+void WaypointList::sort(Compare cmp)
+{
+  std::stable_sort(begin(), end(), cmp);
+}